VB.NET VB6 VB5 VBA
The feature allows you to add or remove line numbers to the source code of a method, class, file, project, or solution / project group. This allows you to use the function of VB.NET / VB / VBA 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
40: Exit Sub
50: MsgBox("Error " & Err.Description & " in line " & Err.Erl & " of Foo")
Although VB.NET allows you to use structured error handling using the statement as follows:
Private Sub Foo()
Dim o As Object
Catch ex As Exception
you may want to use the old error handling mechanism of in the following scenarios:
- You have migrated legacy code from 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 method name are shown in the exception message, but not the specific line number.
offers the following ways to add / remove line numbers:
- The and menus.
- The and buttons on the toolbar.
- In , the keyboard shortcut associated with the . and . commands.
- In , the keyboard shortcuts associated with the feature.
- In , the menu entries on the context menu of a project or file in the Project Explorer and the context menu of the code window.
When you invoke this feature:
- If the cursor is inside a method, the feature is executed only for that method without further action.
- Otherwise, a window is shown that allows you to select the scope of the operation (the most suitable is preselected) and to decide whether or not to keep open the modified documents:
- Ensure that the source code can be compiled without errors before running this feature.
- The best practice is to avoid the use of line numbers during development, because they are not needed to code and debug, they get messed with the indentation of code and you need to renumber if you add new lines of code. Instead, you should add line numbers just before making the executable (VB6 / VB5 / Visual Studio) or just before distributing a copy of the Office document with VBA code to the end users. In both cases, you need to make a copy of the code with line numbers somewhere (under source control or in backup folders). You can automate the add/remove line numbers features from a script. See Automating Features.
- does not allow line numbers greater than 65535 (they are treated as 0), so resets the numeration when it reaches that limit. Take this into account if you use unique numbers (rather than numbers that reset at method or file level) when numbering a whole project.
- 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, does not number the first statement of a block to avoid that VB error.
- This feature doesn't support using XML literals in Visual Basic .NET. You can skip numbering some specific method defining a attribute somewhere in your project and applying it to the methods that you don't want to add line numbers, as shown in this example:
Public Class SkipMZToolsLineNumbering
Public Class C1
Private Sub f1()
Line Numbering Options
Keyboard Shortcuts Options