THE BREAKPOINTS WINDOW

A breakpoint is a line of code that you have flagged to stop execution. When the program reaches that line, execution stops and Visual Studio displays the code in a code editor window. This lets you examine or set variables, see which routine called the one containing the code, and otherwise try to figure out what the code is doing.

The Breakpoints window lists all the breakpoints you have defined for the program. This is useful for a couple of reasons. First, if you define a lot of breakpoints, it can be hard to find them all later. Although other commands let you disable, enable, or remove all of the breakpoints at once, at times you may need to find a particular breakpoint.

A common debugging strategy is to comment out broken code, add new code, and set a breakpoint near the modification so that you can see how the new code works. When you have finished testing the code, you probably want to remove either the old code or the new code, so you don’t want to blindly remove all of the program’s breakpoints.

The Breakpoints window lists all of the breakpoints and, if you double-click a breakpoint in the list, you can easily jump to the code that holds it.

Right-click a breakpoint and select Condition to display the dialog box shown in Figure 6-3. By default, a breakpoint stops execution whenever it is reached. You can use this dialog box to add an additional condition that determines whether the breakpoint activates when it is reached. In this example, the breakpoint stops execution only if the expression (n < 10) AndAlso (result > 1000) is True when the code reaches the breakpoint.

FIGURE 6-3: The Breakpoint Condition dialog box lets you specify a condition that determines whether Visual Studio stops at the breakpoint.

image

NOTE
Note that specifying a breakpoint condition can slow execution considerably because Visual Basic must evaluate the condition frequently.

Right-click a breakpoint and select Hit Count to display the Breakpoint Hit Count dialog box shown in Figure 6-4. Each time the code reaches a breakpoint, it increments the breakpoint’s hit count. You can use this dialog box to make the breakpoint’s activation depend on the hit count’s value.

FIGURE 6-4: The Breakpoint Hit Count dialog box lets you make a breakpoint’s activation depend on the number of times the code has reached it.

image

From the drop-down list you can select one of the following options:

  • Break Always
  • Break When the Hit Count Is Equal To
  • Break When the Hit Count Is a Multiple Of
  • Break When the Hit Count Is Greater Than or Equal To

If you select any but the first option, you can enter a value in the text box and the program will pause execution when the breakpoint has been reached the appropriate number of times. For example, if you select the option Break When the Hit Count Is a Multiple Of and enter 2 into the text box, execution will pause every second time it reaches the breakpoint.

Right-click a breakpoint and select When Hit to display the When Breakpoint Is Hit dialog box. This dialog box lets you specify the actions that Visual Basic takes when the breakpoint is activated. Select the Print a Message check box to make the program display a message in the Output window. Select the Continue Execution check box to make the program continue running without stopping after it displays its message.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.226.98.34