The Watch window the glasses icon

The Watch window lets you monitor one or more of the variables or cells or whatever as the program runs. Clicking this icon or choosing Add Watch. from the Debug menu will prompt the user with a dialog box as shown in Figure 8.5. In the case of the validateWeekSales program we are interested in watching the range variable cell, since this is going to contain the values of the input used in the tests. As you can see in Figure 8.5, this has been entered in the Expression box (all other list boxes and radio buttons have been left with the default values unchanged).

Click OK and you will see a split horizontal window VBE display (Figure 8.6). Notice that the bottom window (title Watches) is the Watch window, and displays four columns:

The first column displays the name of the expression (i.e. cell).

The second column displays the v alue. Before running the macro it is shown to be '< Out of Context >' since it does not know what its value is until the program is running.

The third column displays the type. Again, the current value is Empty since a value will not be assigned until the program is running. Finally, the fourth column displays the context. The display tells us that the context is othersalesmanmacros.validateWeekSales. In other words, this

Figure 8.5 The Add Watch window

I Microsoft Visual Basic - SALESMAN.xls - [othersalesmanmacros (Code)]

File Edit View Insert Format Debug Run Tools Add-Ins Window Help

idxi

H f ualidateWfeekSales iveSheet.Unprotect cell As Object

Each cell In Range("Week_sales"

Context applied to which macros in which module(s)

If Not IsNumeric(cell

HsgBox "Please Enter

Expression

Value

With cell.Interior . Colorlndex = : .Pattern = xlSoli .PatternColorIndex = x End With

LAutomatic cell" £ ci

Type of variable

Expression

6-d cell lvalue

<Out of context>

Empty othersalesmanmacros .vaiidateWeekSales

The Watch window

Figure 8.6 The Watches window before running the program macro is stored in the othersalesmanmacros module and is called validateWeekSales. Having set the watch we now need to set a breakpoint so that w e can pause during each loop execution to see what is happening to the cell.

0 0

Post a comment