Tip: Some very nice VB6 websites

Still using Visual Basic 6 ?  So am I !

Here are some useful VB6 reletaed websites:

Trick: Put line numbers in your VB6 code with this undocumented feature

It’s possible to use line numbers in VB6, just like in old BASIC style code, see below example. Just start new standard project in VB6 (Project1.vbp with Form1 in it, for example)

Then write a code like this in Form_load event (see the like numbers before the actual code):

Private Sub Form_Load()
1 Dim x As Integer
2 On Error GoTo Error
3 x = 2
4 x = x / 0
5 Exit Sub
6 Error:
7 Debug.Print Err.Number
End Sub

Now, set a breakpoint on line 2, and run it (F8). Vb6 stops when it hits the breakpoint. From there, go step by step, one line at the time.  Line 4 produces “division by zero” error, so the execution will jump on line 6. Just step one more time, into line 7. You should see something like this on your screen:

Now, test the Err.Number value, just type in Immediate window? “? Err.Description” = >  you should get “Division by zero”.  Nothing new here, but with the help of another undocumented feature, Erl command,  we can find out the actual line number where the error happened. Just type “? Erl” and you should get “4″ as a response. This means that the last error happened in line number 4 on the code that is in the current scope.

This trick is useful if you have some hard to debug error in your code and you can’t just point finger on the exact line of code where it happens.

Tip: Visual basic 6 error codes

All VB6 error codes listed here:
3     Return without GoSub
5     Invalid procedure call
6     Overflow 
7     Out of memory 
9     Subscript out of range 
10    This array is fixed or temporarily locked 
11    Division by zero
 Read the rest of this entry »
Posted in Tools, VB6. Tags: . 3 Comments »

Tip: String concatenation in VB6

You might thing that it doesn’t matter if you concatenate strings in VB6 with plus ‘+’ or ampersand ‘&’ caracter. Actually it doesn’t if you are concatenating only strings (or if you think that you are concatenating strings)

See below example:

Simple one form project:

Code in Form1:

</pre>
Option Explicit
 Private Sub Form_Load()
   Dim strCC1 As String
   Dim strCC2 As String
   Dim intNBR As Integer
   intNBR = 1

   strCC1 = "Concat &" & intNBR
   strCC2 = "Concat +" + intNBR
 End Sub
<pre>

If you try to run this , you see that the first concatenation works, and the second one doesn’t !

First one does automatic conversion from integer to string. Second one fails because if tries to concatenate interger to string without converting it to string first.

VB6 Resource Editor

In VB6 you can use resource files (.res) to store user messages, icons and pictures. I have to maintain a lot of VB6 code that uses .res files, but my VB6 installation doesn’t come with Resource Editor Add-in (don’t know why). Without Resource Editor I cannot edit those files (they are in binary format). Fortunatelly it’s possible to install manually add-in into VB6. First you must obtain and copy resedit.dll (version 6.0.0.8450 is fine for me) to “C:\Program Files\Microsoft Visual Studio\VB98\Wizards”. Then load it on VB6 Add-in manager, choosing “Add-Ins/Add-in Manager” then “VB 6 Resource Editor” and finally “Load Behaviour Loaded/Load on StartUp”.

VB6 Resource Editor

Finally, you should see this icon on VB6 toolbar add-in-manager-icon.jpg

Download it here: http://www.pcrepaircentral.com/dlldownload_22596.html

Check the file version here: http://www.programchecker.com/file/10069.aspx

Follow

Get every new post delivered to your Inbox.