Section 11.3VB2005's classes have full object-oriented capability, including inheritance, polymorphism, and abstraction. |
Appendix D. Visual Basic Debugging Tools
Errors in programs are called
Another method of debugging involves placing MsgBox statements at strategic points in the program and displaying the values of selected variables or expressions until the error is
The Visual Basic debugger offers an alternative to desk checking and MsgBox statements. It allows you to pause during the execution of your program in order to view and alter values of variables. These values can be accessed through the Immediate, Watch, and Locals
|
The Three Program ModesAt any time, a program is in one of three modes design mode , run mode , or debug mode . (Debug mode is also known as break mode .) When the current mode is "run" or "debug," the words "Running" or "Debugging" are displayed (in parentheses) in the Visual Basic title bar. The absence of these words indicates that the current mode is "design." (This item is displayed on page 627 in the print version)
Title bar and
Title bar and toolbars during run mode.
Title bar and toolbars during debug mode.
With the program in design mode, you place controls on a form, set their initial properties, and write code. Run mode is initiated by pressing F5 or the Start button. Debug mode is invoked automatically when a run-time error occurs. You can use Debug options to break the program at specified places. While the program is in debug mode, you can hover the cursor over any variable to obtain its current value. Also, you can use the debugging
|
Stepping through a Program
The program can be executed one statement at a time, with each press of an appropriate function key executing a statement. This process is called
stepping
. After each step, values of
When a procedure is called, the lines of the procedure can be executed one at a time, referred to as
stepping into
the procedure, or the entire procedure can be executed at once, referred to as
stepping over
a procedure. A step over a procedure is called a
procedure step
. In addition, you can execute the remainder of the current procedure at once, referred to as
stepping out
of the procedure. The three toolbar
Figure D.1. The toolbar buttons used to Step Into, Step Over, and Step Out.
As another debugging tool, Visual Basic allows the programmer to specify certain lines as
breakpoints
. Then, when the program is run, execution will stop at the first breakpoint reached. The programmer can then either step through the program or continue execution to the next breakpoint. Also, the programmer can place the cursor on any line in the program and have execution stop at that line with a "Run to Cursor" command. Program execution normally proceeds in order through the statements in the procedure. However, at any time the programmer can specify the
The tasks discussed previously are summarized next, along with a means to carry out each task. The
|