![]() |
![]() |
![]() |
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
![]() |
![]() |
To access the contents, click the chapter and section titles.
Visual Basic 6 Programming Blue Book: The Most Complete, Hands-On Resource for Writing Programs with Microsoft Visual Basic 6!
While your program is paused at a breakpoint, you have the following execution commands available to you. They are located on the Run menu, represented by toolbar buttons:
While a program is paused, you can track down bugs in a number of different ways. These are covered in the following sections. Using Watch Expressions A watch expression is a Basic expression whose value is monitored, or watched, during program debugging. A watch expression can be any Basic expressiona program variable, an object property, a function call, or a combination of these elements. You can use any of Visual Basics mathematical and logical operators, as well as its built-in functions, to create a watch expression. As mentioned earlier, a prime cause of program bugs is a program variable or property taking on an inappropriate value. By setting a watch, you can keep an eye on the value of the variable or property to see if and when it changes. You can use a watch expression in several ways:
To set a watch expression, select Add Watch from the Debug menu. Visual Basic will open the Add Watch dialog box, which is shown in Figure 26.1. If the editing cursor is on the name of a variable or property at the time you display the dialog box, the variable or property name will automatically be entered in the Expression box in the Add Watch dialog box (as is Total in the figure). Also, if you first select a Basic code expression, then the selected code will be entered here. Next, you will need to enter or edit the desired watch expression in the Expression boxunless, of course, the desired expression was entered automatically. Finally, select the desired type of watch in the Watch Type section of the dialog box, then click on OK. (The Context setting in the Add Watch dialog box will be explained later.) When you add a watchno matter what type it isit will be displayed in the Watches window, as shown in Figure 26.2. Each watch expression is displayed on its own line. The icon at the left end of the line identifies the type of watch (watch, break when changes, or break when True). When you first add items to the Watches window (also shown in Figure 26.2), the Value column displays <Out of context>, and the Type column displays Empty. These will change when the program executes.
Lets look at some watch expression examples. Table 26.1 lists the purpose, type, and expression for a variety of debugging situations. When you execute a program where watches are set, every time the program breaks, the information displayed in the Watches window is updated. This occurs regardless of whether the break was caused by a breakpoint set on a line of code or by a Break When Value Changes or Break When Value Is True watch expression. Then, the Watches window displays the following:
Working In The Watches Window While the program is in break mode, you can do several things in the Watches window to assist your debugging. Right-click on any watch expression to display the shortcut menu shown in Figure 26.3. Your choices are:
You can also modify the value of variables in the Watches window. Click on any watch expression once to highlight it, then click on the value displayed in the Value column. You can now edit the displayed value. When you move off the line by clicking on another expression or pressing the up or down arrow key, the variable takes on the value you entered. This value will remain in effect when you continue program execution. Youll find this technique useful for testing the effects that different variable values will have on the program execution.
|
![]() |
Products | Contact Us | About Us | Privacy | Ad Info | Home
Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc. All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited. Read EarthWeb's privacy statement. |