Wednesday, February 09, 2005

I just learned about this and had to post it right away.  Does anyone remember their old-school BASIC programming?  Stuff like:

10:  PRINT HELLO
20: GOTO 10

BASIC used line number labels to identify where in the program execution should occur.  Visual Basic did away with line numbers as a requirement, but did not get rid of line number support.  There was even a documented feature in Visual Basic 3, Erl() which allowed you to get the last successfully executed line number in your source code.  Documentation of this feature disappeared in VB4, but support for it has continued even through VB.Net (it is now sparsely documented)!  That means you can enhance your error logging functions to include which exact line of your source code failed.  For example:

10:     On Error Resume Next
20:     Err.Raise(60000)
' Returns 20.
30:     MsgBox(Erl())

There is an excellent article on Addison-Wesley’s site which illustrates how helpful line numbers and Erl() can be in your debugging.

For VB6 and earlier, there was an excellent free tool from MZ-Tools which could automate line numbering.  MZ-Tools does have a release for VB.Net, but the tool seems to no longer support line numbering.  I don’t know of any product which helps you do this.

— Matt Ranlett

2/9/2005 7:26:53 PM (Eastern Standard Time, UTC-05:00)  #    Trackback
Tracked by:
"Keeping the Visual Basic group Regular" (Atlanta .NET Regular Guys) [Trackback]
"Strip Poker Games Online" (Strip Poker Games Online) [Trackback]