The Watch Window

The Watch window is a tool that allows you to set conditions on which you can put your code into break mode. The Watch window, shown in Figure 7-33, has a few options as to how to handle watched values.

Figure 7-33. The Watch window

You enter an expression in the Expression text box, and then select the context of the expression from the Procedure and Module drop-down lists. Then you select a watch type. Watch types are described in Table 7-3.

Table 7-3. Watch Types

Watch Type_Description_

Watch Expression Code execution will not be stopped. In break mode, the values of watched expressions will be displayed in the Watch window.

Break When Value Is True Code execution will enter break mode when the watched value is


Break When Value Changes Code execution will enter break mode when the value of the watched expression changes.

In this example, we'll add a watch to the GetSalesTotal function and set it to break when the value is True.

1. Open the VBE and open Standard Module2.

2. Display the GetSalesTotal function.

3. Right-click any occurrence of the variable cell in the For Each...Next loop.

4. Select Add Watch from the shortcut menu, as shown in Figure 7-34.

Figure 7-34. Selecting the Add Watch command 5. Enter the information shown in Figure 7-35 into the Add Watch dialog box.

Expression: cell.Value <3a:'

Procedure: GetSales Total

Module: Modules

Project: VBAProject

-Watch Type

Watch Expression 11 When Value Is True!

C Break When Value Changes

Figure 7-35. Adding a watch expression

0 0


Post a comment