Q: I’m trying to use the Debugger more, but find it hard to know where to put SET STEP ON in my code to help me find problems. Is there a better way to stop code execution?
A: There are a number of better ways to get access to running code than SET STEP ON. (In fact, I can’t remember the last time I used SET STEP ON or its alter-ego, SUSPEND.) The key to stopping code so you can step through it is breakpoints. A breakpoint stops execution and lets you take a look at what’s going on.
Breakpoints come in two basic flavors, those based on where you are in the code and those based on the value of an expression. VFP lets you set both kinds, as well as a hybrid of the two, and provides several ways to set each.
The most obvious way to set breakpoints is by using the Breakpoints dialog (figure 1), available from both the VFP menu and the Debugger. The Type dropdown lets you choose the kind of breakpoint to create. There are four choices:
- Break at location -- stop execution before running the specified line;
- Break at location if expression is true -- stop execution before running the specified line, but only if the specified expression evaluates to True.
- Break when expression is true -- stop execution at the end of the line in which the specified expression becomes True.
- Break when expression changes --stop execution at the end of the line in which the value of the specified expression changes.