One way to view the value of variables is with the Watch window. This window, shown in Figure 6.17 will show you the expression you are watching, the value of the expression, the type of watch, and the procedure where the expression is being evaluated. Using the Watch window allows you to look at only the variables or expressions which interest you. You can access the Watch window from the Debug toolbar or by selecting the WatchWindow item from the View menu.
The Watch window shows the value of variables and expressions you define.
To set up a variable or expression for viewing, you have to add it to the Watch window. To do this, you choose the Add Watch option from the Debug menu. This brings up the Add Watch dialog as shown in figure 6.18. The dialog allows you to enter the name of the variable to observe in the Expression field.
The Add Watch dialog lets you set up variables to observe during program execution.
The Add Watch dialog also allows you to specify where you want to observe the variable. These context settings let you observe the value of the variable during the entire program or just during a specific procedure.
The Watch Type options let you decide whether to just look at the value of the variable or to break (pause the execution of the code) when a specific condition exists. You can choose to have the program pause every time a variable changes or when the watch expression is True. This way you can determine when a variable reaches or exceeds a specific value. To use this type of watch, the expression must be a Boolean variable or a logical expression.
If at a later time, you wish to edit the watch expression, you can right-click the mouse in the Watch window and select the Edit Watch item from the pop-up window. This brings up the Edit Watch dialog which is basically the same as the Add Watch dialog, but adds a command button that allows you to delete the watch.