SEARCH
0-9 A B C D E F G H I J K L M N O P Q R S T U V W X Y Z
Prev | Current Page 243 | Next

Jim DeMarco

"Pro Excel 2007 VBA"


We can use any of the following to view variable values:
??? The Immediate window
??? The Locals window
??? The code window
CHAPTER 7 n DEBUGGING AND ERROR HANDLING 267
The Immediate Window
To check the value of a variable in the Immediate window, simply type the name of variable
and its value will be displayed.
1. In the Immediate window, type ?i.
2. Press Enter.
3. In the Immediate window, type ?lngResult.
4. Press Enter.
Figure 7-25 shows that this returns the values 11 (since our loop reached its last iteration)
and 0, respectively.
Figure 7-25. Checking the value of variables in the Immediate window
5. To run the code to the end from the current execution point, press F5.
nTip Did you know that you can test loops from within the Immediate window? Just type them using the
following syntax:
for i = 1 to 5:debug.print "Test " & i:next i
The result of running this is shown in Figure 7-26.
Figure 7-26. Testing loops in the Immediate window
CHAPTER 7 n DEBUGGING AND ERROR HANDLING 268
The Locals Window
The Locals window lets you see all current variables and their values in break mode in one
place. To see the Locals window at work, we are going to run an existing macro in the
DebugExample01.xlsm file against the sales data on Sheet1.
We saw this data and code in our 1-MacroExample01.xlsm file in Chapter 1. In this example,
the data has been slightly modified and will generate an error that we??™ll track down using
the tools explained thus far.


Pages:
231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255