212 Part II Programming Fundamentals
Debugging 101: Using Debugging Mode
One way to identify a logic error is to execute your program code one line at a time and examine
the content of one or more variables or properties as they change. To do this, you can enter
debugging mode (or break mode) while your program is running and then view your code in the
Code Editor. Debugging mode gives you a close-up look at your program while the Visual
Basic compiler is executing it. It’s kind of like pulling up a chair behind the pilot and copilot
and watching them fly the airplane. But in this case, you can touch the controls.
While you’re debugging your application, you’ll use buttons on the Standard toolbar and the
Debug toolbar, as well as commands on the Debug menu and special buttons and windows
in the IDE. The following screen shot shows the debugging buttons on the Standard
and Debug toolbars, which you can open by pointing to the Toolbars command on the View
menu and then clicking Standard or Debug. In this chapter, you’ll use the Immediate, Locals,
Start Debugging, Stop Debugging, and Step Into commands.
Immediate
Locals
Watch
Start Debugging
Stop Debugging
Step Into
In the following exercise, you’ll set a breakpoint—a place in a program where execution
stops. You’ll then use debugging mode to find and correct the logic error you discovered
earlier in the If... Then structure. (The error is part of an actual program .) To isolate the
problem, you’ll use the Step Into button on the Standard toolbar to execute program
instructions one at a time, and you’ll use the Autos window to examine the value of key
program variables and properties. Pay close attention to this debugging strategy. You can
use it to correct many types of glitches in your own programs.
Debug the Debug Test program
- Start Visual Studio.
- On the File menu, click Open Project.
The Open Project dialog box opens.
- Open the Debug Test project in the C:\Vb10sbs\Chap08\Debug Test folder.
The project opens in the development environment.