Setting Breakpoints

A breakpoint is a setting that you can add to a line of code to temporarily pause execution at that line. Whenever code execution is halted because of a breakpoint, the code is said to be in break mode. The purpose of a breakpoint in Visual Studio is identical to that in VBA; however, as described later in this chapter, enhancements have been made to breakpoints in Visual Studio. Typically, you set breakpoints to pause code execution so that you can check the value of a variable or check for logic errors by stepping through the code one line at a time.

You can add a breakpoint to an executable line of code by selecting Toggle Breakpoint from the Debug menu. You can also add a breakpoint by clicking the area to the left of a line of code. Keep in mind that breakpoints cannot be added to just any line of code. You cannot add breakpoints to lines that contain only code comments or blank spaces.

A number of debugging windows become available only when your application is in break mode. These windows, located in the Debug menu, include the Watch window, the Locals window, and the Call

Stack window. You can also access these windows by right-clicking a line of code and choosing the window from the shortcut menu.

When you add a breakpoint, the line of code is highlighted and a red circle appears to the left of the line. The additional breakpoint features in Visual Studio are available in a shortcut menu, as shown in Figure 2.34. To access these options, right-click a breakpoint in the Code Editor.

Figure 2.34. The options for a breakpoint

The breakpoint options enable you to specify conditions for a breakpoint, edit its location, or assign a custom action (known as setting a trace point). Let's look at each option.

0 0

Post a comment