Debugging Scripts
Debugging is the process of figuring out what the error message you're getting actually means, how it relates to what you've done in your script, and what you need to do to correct it. Although an error capture script (see "Creating an Error Trap Script" later in this chapter) can help you with the first step, you have to apply that knowledge to your specific situation.In addition, not all script problems generate error codes. Everything in the script can be technically correct (no missing fields, no endless loops, no problem sorts) and still not do what you want it to do. When that happens, you need to debug the script from scratch.There are three major places to check when a script goes wrong:The Specify options.
The easiest error to make is forgetting to set sort, find, or print options in the Script Step Options section. Checking these options is the first debugging step if you have no error codes but your script doesn't give you the records you expect.Step order.
It's easy to add a step in the wrong place, particularly if you're adapting an existing script. Using the Pause Script, Halt Script, and Exit Script steps, you can stop a script at any stage to isolate the problem.Pause Script stops everything until you click Continue or Cancel in the status area. You can set several Pause Script steps in strategic places in a long script to help you figure out where to concentrate your debugging efforts. The Exit step stops the running script. This helps you figure out whether your problems are in the main script or are really based in the sub-script it uses. The Halt step brings all scripts to an end at whatever point you place it. Halt is particularly useful for troubleshooting loops.Conditional statements.
Even expert scripters occasionally put the item they want as the Else condition into the If step instead. When you have a nested If script (one If step inside another), it's all too easy to get confused. An error trap script is particularly useful in trouble shooting an If statement.
To use the Halt, Pause, or Exit Script commands
1 .Choose Scripts > ScriptMaker (Control+Shift+S/Command+Shift+S).2 .Double-click the script you want to check. Our example, Export by Payment, has many sub-scripts, and we want to check which one is causing problems.3 .In the script-assembly list in the Script Definition dialog box, click to select the step that you want to check. In our example, it's Export Checks (Figure 10.14).
Figure 10.14. Highlight the script step you want to check.

Figure 10.15. The Halt command will stop all running scripts wherever you place it.

Figure 10.16. After you've debugged the script, remove the Halt step.
[View full size image]
