Home | Tips | Library | Other Authors | Other WP Sites | Writer's Links | Contact | Site Map | Donate

Barry MacDonnell's
Toolbox for WordPerfect

Macros, tips, and templates for Corel® WordPerfect® for Windows®
© Copyright 1996-2017 by Barry MacDonnell. All Rights Reserved.

Page updated Jun 21, 2012

WordPerfect Tips
Main tips page | Browse tips
Simple tricks
to help debug
your macros
Two simple methods

Back up your macro first.

Method #1 - slow down the macro to see what's happening

If you've created a macro that doesn't seem to work right or it just freezes up when you play it, here's a simple trick to help you figure out what's wrong:

Edit the macro, and on the line under the "Application( ... )" command -- generally this is the first line in your macro, so start on line 2 -- add these two commands:

Display (On!)
Speed (1)

On the Macro Toolbar, click Save & Compile.

Turn WordPerfect's Reveal Codes window ON, then play the macro. Watch what happens in the Reveal Codes window. You may be able to tell where the macro is going wrong as it executes its commands.

When you are done fixing things (also see the TIP below), delete the Speed() command and restore the Display command from Display(On!) to Display(Off!).

The first command, Display(On!), will display all events during the macro's playback (if you get any dialog box error messages such as "... not found," just click OK and the macro should continue). Be sure there isn't a Display(Off!) under these commands; if there is, delete it or comment it out with double forward slash marks.

The Speed() command slows down the macro's execution. You can set this to a higher number than "1" to really slow it down. As the macro plays, watch the screen and the Reveal Codes window. [More recent versions of WordPerfect support the Step() command (see below), but new users may find the Speed() command easier to use and understand.]

Method #2 - stop the macro at different points

You can also edit the macro and add the single command -

Quit 

- near the top after the first commands that perform some action, then Save & Compile. Quit causes the macro to stop immediately at that point. 

Play the macro: If things worked OK to that point, delete the Quit command and enter another QUIT command further down in the macro code. 

Repeat the process until you find the segment of code that is causing the problem.

A slightly more advanced method

Back up your macro first.

Method #3 - "step" through the macro with key presses

Edit the macro. Add these two commands at the top of the code after any Application() command.

Display(On!)
Step(On!)

On the Macro Toolbar, click the Options button and check (enable) "Compile with Debug." 

Then click on Save & Compile.

Open the document the macro is to be played on. Open Reveal Codes (View, Reveal Codes) so you can observe the actions of the macro as it steps through its commands.

Play the macro. The PerfectScript Compiler Listing dialog appears, showing the name of a "listing" file that will be created. 

Click on OK (you can overwrite any existing .WCL listing file). The macro will start. 

When the macro reaches a new line of code, PerfectScript shows a new window, the PerfectScript Debugger. Drag it out of the way. F8 single-steps, F9 sets/removes a breakpoint, F5 runs the macro to the next breakpoint or the end of the macro. (Usually you have to tap F5 twice, to prove you really meant it.)

When done debugging: (1) remove the check mark from Options, "Compile with Debug"; (2) Remove Display(On!) and Step(On!); and (3) click Save & Compile.

Note: In the same folder as the macro you may find a file with the same name as the macro but with a .DBG extension. There may also be one with a .WCL extension. You can delete both.

[Thanks to Roy ("lemoto") Lewis for this tip.]