When Visual Basic encounters a breakpoint while executing a procedure, it enters break mode just before executing the breakpoint line. You can set or remove a breakpoint when you're writing code in a module or whenever you're in break mode. When you set a breakpoint, Visual Basic highlights the breakpoint line with a dark red background. Visual Basic also displays a rectangular outline around the statement at which the procedure is suspended. This outline indicates the current statement, or the next statement to be executed.
To set a breakpoint
1. In the module, move the insertion point to a line of code that isn't already a breakpoint.
Toggle Breakpoint
button
2. On the Run menu, click Toggle Breakpoint, or click the Toggle Breakpoint button on the Visual Basic toolbar.
To clear a breakpoint
1. In the module, move the insertion point to the line of code that's the breakpoint you want to clear.
2. On the Run menu, click Toggle Breakpoint, or click the Toggle Breakpoint button on the Visual Basic toolbar.
After a breakpoint occurs, you can examine what's happened up to that point by inspecting code and data in the Immediate pane of the Debug window and by using the Calls dialog box. For more information about the Calls dialog box, see "Using the Calls Dialog Box to Trace Nested Procedures" later in this chapter.
If the problem you're trying to solve has already occurred, you know that a previously executed line of code is causing the problem. If not, a line of code that has not executed yet is causing the problem. If the breakpoint line is the cause, the problem won't occur until you execute at least one more statement. After you enter break mode, you can step through your code line by line to find the problem, as discussed later in this chapter.
Important
The problem may be something other than a line of code. A statement can be the indirect cause of the problem if it assigns an incorrect value to a variable. You can examine the values of variables while you're in break mode. For more information, see "Inspecting Code and Data in the Immediate Pane" later in this chapter.