Debugging Tips

When your macro does not produce the expected results, work through the following steps to narrow the problem down:

  1. Begin by browsing through your macro looking for actions that may be related to the behavior you are seeing.
  2. Set a breakpoint at any potentially relevant action and restart the macro in debug mode.
  3. When the macro halts, test the values of any related variables and properties.
  4. If an error occurs in a loop, define a break expression inside the loop to determine where the problem occurs.

Run-time errors versus logic errors

To understand how debugging is useful, consider the types of errors you can encounter:

Run-Time Errors

Run-time errors occur while the macro is running. They are detected by Newlook when a statement attempts an operation that is impossible to carry out. An example of this is division by zero.

Suppose you have this action:

SetValue (UnitPrice, TotalCost / Units)

If the variable Units contains zero, the division is an invalid operation, even though the statement itself is syntactically correct. The macro must run before it can detect this error.

Logic Errors

Logic errors occur when a macro doesn't perform the way it was intended. A macro can have syntactically valid code, run without performing any invalid operations, and yet produce incorrect results. Only by testing the macro and analyzing results can you verify that the macro is performing correctly.

An example of a logic error could be:

SetValue (UnitPrice, Units / TotalCost)

In this example the action has used the wrong calculation when attempting to determine the unit cost.

How Debugging Tools Help

Debugging tools are designed to help you with:

For instance, an incorrect result may be produced at the end of a long series of calculations. In debugging, the task is to determine what and where something went wrong. Perhaps you forgot to initialize a variable, chose the wrong operator, or used an incorrect formula.

Debugging helps you understand what's going on while your application runs. Debugging tools give you a snapshot of the current state of your application, including:

Other Considerations

Certain events that are a common part of using Microsoft Windows can pose special problems for debugging an application. It's important to be aware of these special problems so they don't confuse or complicate the debugging process.

If you remain aware of how break mode can put events at odds with what your application expects, you can usually find solutions. In some event procedures, you may need to use MsgBox action to monitor values of variables or properties instead of using watch expressions or breakpoints. You may also need to change the values of variables that depend on the sequence of events.

Breaking Execution During GotFocus or LostFocus

If you break execution during a GotFocus or LostFocus event, the timing of system messages can cause inconsistent results. Use a MsgBox action instead of a breakpoint in GotFocus or LostFocus event procedures.

Modal Dialogs and Message Boxes Suppress Events

The development environment cannot display and interact with the Macro Editor debugger while a modal form or message box is displayed. Therefore, the modal form or message box must be dismissed before you can interact with the debugger again.

See Also

Debugging Macros | Using Inspector | Writing and Debugging Macros