30.04.2017 Views

4523756273

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Chapter 13: Bug Extermination Techniques<br />

207<br />

Execute your procedure after setting up your watch expression(s). Things run<br />

normally until your watch expression is satisfied (based on the Watch Type<br />

you specified). When that happens, Excel enters Break mode (you did set the<br />

Watch Type to “Break When Value Is True,” didn’t you?). From there, you can<br />

step through the code or use the Immediate window to debug your code.<br />

When you create a watch, VBE displays the Watches window shown in Figure<br />

13-8. This window displays the value of all watches that you’ve defined. In this<br />

figure, the value of Counter hit 900, which caused Excel to enter Break mode.<br />

Figure 13-8:<br />

The<br />

Watches<br />

window<br />

displays all<br />

watches.<br />

The best way to understand how this Watch business works is to use it and<br />

try various options. Before long, you’ll probably wonder how you ever got<br />

along without it.<br />

Using the Locals Window<br />

Another useful debugging aid is the Locals window. You can show this<br />

window by choosing View➪Locals Window from the VBE’s menu. When you<br />

are in Break mode, this window will show you a list of all variables that are<br />

local to the current procedure (see Figure 13-9). The nice thing about this<br />

window is that you don’t have to add a load of watches manually if you want<br />

to look at the content of many variables. The VBE has done all the hard work<br />

for you.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!