The Call Stack Shows Where You've Been

At any point during the debugging session, you can click the Debug toolbar button's Call Stack button to display the Call Stack window.

The Call Stack window shows where your program execution has traveled. In addition, any non-Visual Basic routines, such as Windows routines that sometimes take over, appear in the Call Stack window. The call stack keeps a running list of all procedures executed, even if the same procedure executes multiple times.

tip

Inside the debugger's break mode, you'll only see the Code window and its related Debug windows that you display. If you want to see the program's actual output, press Alt+Tab to switch to the application's running window.

Suppose that a variable contains an incorrect value but you're not exactly sure where the error is occurring. You could set a breakpoint at every line of code that changes the variable. When you run the program, you'll look at the contents of that variable before and after each breakpoint's line of execution. If the first breakpoint seems to initialize the variable properly, you don't have to single-step through the code until the next breakpoint is reached. Instead of single-stepping, you can select Run[hr]|[hr]Continue or press F5 to return the execution to its normal runtime (and real-time) mode. When Visual Basic reaches the next breakpoint, the code halts at that next breakpoint and you can continue to examine the variable.

At a breakpoint, you can add not only variables but Watches window expressions as well. Suppose that a variable is to maintain a count of customers but somewhere in your code a negative value appears in the variable. You can debug this problem by adding a watch expression such as intCustCnt < 0 to the Watches window. To do this, right-click the window and select Add Watch to display the Add Watch dialog box. Click the window's Break When Value Is True option button. You can then run the program and Visual Basic would enter break mode at any line that caused the variable to become negative.

The breakpoints and watch dialog boxes that you can request while debugging your code give you tremendous power in analyzing variables and watching for specific results. You can look at the contents of variables and controls to make sure that data is being initialized the way you expect. Also, the Add Watch dialog box lets you set up expressions that Visual Basic watches for during the program's execution. If the values of those expressions ever become true or change, Visual Basic halts the code at that line and lets you analyze values using the Watch window.

Top Home