Macro Programming Tips
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:
- Font size.
Increase the font size in your macro documents to make the code
easier to read. As that simple idea stretches into a late night macro
programming session, an easy-to-read 14 or 16 point font size will
help avoid errors and eye strain.
- Header.
Start each macro with a comment, identifying the author name and
phone number, revision date, macro name, purpose, and copyright
notice (as appropriate).
- Macro Manual.
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.
- Highlight key code.
Use Redline, Bold, and font colors to add emphasis to key parts of
your code, such as labels, variables, subroutines, etc.
- Label@.
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@).
- "Go To Line Number" button.
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.
- Comment key code.
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.
- Gordon McComb.
Author Gordon McComb is the macro man. Read his books and check his web site (www.wpuniverse.com).
- Read the help.
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.)
- Hard return code.
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:
HRt=NTOC(0F90Ah) (— that's zero, F, nine,
zero, A, H)
Here's an example that forces the text onto two lines:
MessageBox(X; "Done!"; "Macro
complete."+HRt+"Use Ctrl+Q to fill in cc:")
- Create a samples file.
As much as possible, avoid reinventing the wheel. Save examples of
good code in a samples file for later cut and paste.
- System Variables.
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.
- OnNotFound.
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).
- Step(on!).
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.
Copyright (C) 2000 by microCounsel. All rights
reserved.
[
Home Page |
Articles List |
Top of this article
]