USING THE WATCH WINDOW TO MONITOR VARIABLE VALUES AND OBJECT PROPERTIES


The Watch window shows the current values of selected variables or expressions and the current property settings for selected objects. You can use the Watch window to monitor the status of variables and objects as you step through a procedure.

To display the Watch window, choose View, Watch Window. (To close the window, click its Close button.) To add a variable or object to the Watch window, you can select it in the Code window and drag it into the Watch window. You can add expressions, such as a + 1, to the Watch window in this manner. Alternatively, you can add something to the Watch window by choosing Debug, Add Watch. In the Expression box of the Add Watch dialog box, type a variable name or other valid VBA expression.

Setting Conditional Breakpoints with the Watch Window:

As Figure 33-4 shows, you can use the Add Watch dialog box to set a conditional breakpoint. Choose Debug, Add Watch, specify the name of a variable or a VBA expression, and then select either Break When Value Is True or Break When Value Changes. Selecting Break When Value Is True for an expression is comparable to using a Debug.Assert statement to set a conditional breakpoint. The difference is that Debug.Assert causes a break when an expression becomes false, and the Break When Value Is True option does the opposite.

Using Quick Watch to Monitor a Variable or Add a Watch Item

In break mode you can select any variable name or expression in your code and choose Debug, Quick Watch (or press Shift + F9) to see the current value of the selected item. If you decide you want to monitor that item continuously, you can click Add in the Quick Watch dialog box. The VBE then adds the item to the Watch window.