|
The feature allows you to add or remove line numbers to the source code of a procedure, class, file, project, or solution. This allows you to use the function of VB.NET in your error handlers to know the exact line number that caused the error:
Private Sub Foo()
10: Dim o As Object
20: On Error GoTo Proc_error
30: MsgBox(o.ToString)
40: Exit Sub
Proc_error:
50: MsgBox("Error " & Err.Description & " in line " & Err.Erl & " of Foo")
End Sub
Although VB.NET allows you to use structured error handling using the statement as follows:
Private Sub Foo()
Dim o As Object
Try
MsgBox(o.ToString)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
you may want to use the old error handling mechanism of VB 6.0 in the following scenarios:
- You have migrated legacy code from VB 6.0 and you want to use the same error handling code.
- You want to know the line that caused an error even in the configuration, since the method of the class only shows the file name and the line number of the error in the configuration (which generates a .pdb debug file). In the configuration the .pdb file is missing, and only the class and procedure name are shown in the exception message, but not the specific line number.
MZ-Tools offers the following ways to add / remove line numbers:
- The and menus.
- The and menus on the toolbar.
- The keyboard shortcut associated with the . and . commands.
When you invoke this feature, a dialog window is shown that allows you to select the scope of the operation.
Remarks:
- Ensure that the source code can be compiled without errors before running this feature.
- Visual Basic does not allow line numbers greater than 65535 (they are treated as 0), so MZ-Tools resets the numeration when it reaches that limit. Take this into account if you use unique numbers (rather than numbers that reset at procedure or file level) when numbering a whole project.
- Visual Basic does not allow a line number in the first statement of a 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 statement of a block to avoid that VB error.
See Also:
Add Line Numbers (VB.NET) Options
Keyboard Shortcuts Options
|