by Kendall Callas
In more than ten years of WordPerfect macro programming, I've accumulated a few tips that will help you write better code. (These tips apply to WordPerfect for Windows versions 5.x, 6.x, 7, 8, and 9, unless noted.) Here are a few of my favorites:
Start each macro with a comment, identifying the author name and phone number, revision date, macro name, purpose, and copyright notice (as appropriate).
There is a separate reference book for macro programmers. If you plan to get serious about macros, order it from the Corel Orders Desk, 800-772-6735. For WP9, a single slim volume is $23 plus shipping; for WP8, two thick volumes cost $66 plus shipping. The WP9 volume is an advanced guide with several fully-commented examples and much discussion of concepts; the two WP8 volumes are more like ordinary programming language documentation, with lists of system variables and commands and their syntax, with sparse examples. The two sets are not redundant, I recommend you get both.
Use Redline, Bold, and font colors to add emphasis to key parts of your code, such as labels, variables, subroutines, etc.
End label names with the @ symbol to distinguish variable names from location references. This makes them easier to search for and avoids accidental use of reserved words, such as Label(Error@) or Label(Cancel@).
In WordPerfect for Windows 5.x, 6.x, and 7, the "Go to Line Number" button (on the Macro Tools toolbar) is extremely handy when debugging, since error messages report the bad line number.
Use comments (//text) to mark points in your code where testing or enhancement is needed. Later it will be easy to find them by using F2/Find to locate //xx markers or keywords in the comments.
Author Gordon McComb is the macro man. Read his books and check his web site (www.wpuniverse.com).
In WordPerfect for Windows 7 and 8, for answers at your fingertips, check out the resources available under Help, Help Topics, Contents, Macros. (In WP 6.x, check Help, Macros.)
It's handy sometimes to use carriage returns and blank lines to format sections of text in prompts and menus. To do so, use the following rather obscure code to define a hard return:
As much as possible, avoid reinventing the wheel. Save examples of good code in a samples file for later cut and paste.
Review the list of system variables (use the Commands button while editing a macro). You'll find gems such as ?UserName, ?Page, ?Line, ?LeftChar, ?CurrentWord, ?SelectedText, ?Path, ?Name, ?Cell, ?InTable, ?Docnumber, ?TypeoverActive, ?BlockActive, ?DocBlank, and ?MarginLeft. You'll be surprised how useful they can be.
Note the dual personality of the OnNotFound command. Terse documentation gives no clue, but this command handles two very different kinds of errors:
- failed text searches, and
- file manipulations that result in a "File Not Found" message (such as FileOpen or FileDelete).
The Step(on!) command is very useful for debugging code. At the point where this command is inserted in your macro, it halts the process and provides a listing of currently defined variables and their values.
[ Home Page | Articles List | Top of this article ]