Figure The Locals and Watches windows

| Pruralai hA

CTOlixTroEt: SomnlcMDdJ c rroc:ii rc^

- iifn ft rr | Va .1=

|Typa

| CniKml

—I

id . 1 3

IttHJSh

SiirelcMad ■

LxuifMlM V-ibW

1 Tre» j.

1 riuyul

i J

l-nngftl

The Locals window shows the values of all local variables. A local variable is a variable defined within the current procedure, and is therefore not valid in any other procedure. (We will discuss local variables in the next chapter.)

The Watches window shows all of the watches that we have set. A watch is a variable or expression that we place in the Watch window. Excel automatically updates the expressions in the Watch window after each line of code is executed and acts according to the type of watch defined, as described in the following list.

To add a watch, choose Add Watch from the Debug menu. This will produce the dialog box shown in Figure 4-11. We can then enter a variable or expression, such as x > 6, in the Expression text box. Note that there are three types of watches:

• Watch Expression simply adds the expression to the Watches window, so we can watch its value as code is executed. In this example, the value of the expression will be either True or False, depending upon whether x is greater than 6.

• Break When Value Is True asks Excel to stop execution and enter break mode whenever the expression is true. In this example, VBA will break execution when x > 6 is true, that is, when x becomes greater than 6.

• Break When Value Changes asks Excel to enter break mode when the value of the expression changes in any way. (In this case, from True to False or vice-versa.)

+1 0

Post a comment