Line Numbering

Top  Previous  Next

The Line Numbering feature allows you add or remove line numbers to the source code of a procedure, file, project or project group (the scope depends on the menu or context menu of the Project Explorer that you use). Line numbering is useful if you use the Erl function in your error handlers to know the line that caused the error:

 

Private Sub Form_Load()

 

10   On Error GoTo Proc_error

20   Debug.Print 1 / 1

30   Debug.Print 1 / 0

40   Exit Sub

 

Proc_error:

 

50   MsgBox "Error " & Err.Description & " in line " & Erl & " of Form_Load"

 

End Sub

MZ-Tools offers the following ways to add or remove line numbers to the source code (notice that each menu has a different scope for the operation):

  • The Tools | MZ-Tools | Add Line Numbers and Tools | MZ-Tools | Remove Line Numbers menus: with these menus you add or remove line numbers to the source code of all the files of all the projects.
  • The Add Line Numbers and Remove Line Numbers context menus of a project in the Project Explorer of Visual Basic: with these menus you add or remove line numbers to the source code of all the files of the selected project.
  • The Add Line Numbers and Remove Line Numbers context menu of a file in the Project Explorer of Visual Basic: with these menus you add or remove line numbers to the source code of the selected file.
  • The MZ-Tools | Add Line Numbers and MZ-Tools | Remove Line Numbers context menus in a code window: with these menus you add or remove line numbers to the source code of the current procedure.
  • The Add Line Numbers and Remove Line Numbers menus on the MZ-Tools toolbar: with these menus you add or remove line numbers to the source code of the current procedure.
  • The shortcut customized in the Options window, Shortcuts tab: with this shortcut you add or remove line numbers to the source code of the current procedure.

You can customize in the Options window, General tab, the increment used when numbering lines. Also, you can customize if unique numbers should be used when numbering a whole project (in this case the counter is not reset in each procedure).

Remarks:

  • Visual Basic does not allow line numbers greater than 65535 (they are treated as 0), so MZ-Tools stops the numeration when it reaches that limit. Take this into account if you use unique numbers when numbering a whole project.
  • If you want to number some line manually, use 5 characters of padding for the number plus an extra space as separator.
  • Do not use the Remove Line Numbers feature to remove line numbers added by another utility, since it can use other padding.
  • Visual Basic does not allow a line number in the first Case of a Select Case block. If you try to add the line number by hand and you hit F5 to run the project, you get the VB error: "Statements and labels invalid between Select Case and first Case". So, MZ-Tools does not number the first Case of a Select Case block to avoid that VB error.

See Also:

Add Error Handler

General Customization

Shortcuts Customization