WORDPERFECT MACRO TUTORIAL


4. Editing Macros

4.1 Editing a macro

Macros can be edited like any WordPerfect document, but they should be opened by clicking on Tools/Macro/Edit rather than File/Open. Doing so brings up the macro toolbar, which you need to save the macro and to insert certain commands. If you open a macro as a regular document, you can access the macro toolbar by clicking on Tools/Macro/Macro Toolbar.

WordPerfect 8 Macro Toolbar

The macro actually consists of macro commands only. (Commands are covered in detail in the next section of the tutorial.) Inserting formatting such as tabs, hard returns, underlining, bolding, line spacing, line numbering, etc., into the macro document while you edit it will format the visual presentation of the macro file when it is opened for editing (like any WordPerfect document). However, this formatting will be ignored when the macro is compiled, and will have no effect when the macro is played. Extra spaces will also be ignored, except where they are part of a string parameter (part of text enclosed in quotation marks).

As with any WordPerfect document, you can type, delete, move and copy text in the macro. Commands that you insert in the macro when editing or programming must be in the exact form required by the macro language, otherwise the commands will not be recognized and you will get an error. WordPerfect macros are not "case-sensitive." This means that for commands and variable names, upper- and lower-case characters are considered identical.

4.2 Compiling a macro

"Compiling" is the process by which a macro is translated into "computer language" (i.e., a form the computer can understand). When a macro is first recorded, it is automatically compiled by WordPerfect. But when a macro is created from scratch by typing the commands into the macro document, or the macro is edited, the macro must be compiled before it can run. That is why the button on the macro toolbar is labeled "Save & Compile."

During compilation, WordPerfect checks for any programming errors. If any are found you will receive an error message detailing the problem, and the location by phrase and line number. (It helps to turn on line numbering in long macros.) Sometimes the mistake is not readily apparent from the error message, because the problem identified by WordPerfect can be caused by a mistake earlier in the macro. A simple typo in a command, a misplaced quotation mark or semicolon, or a missing parenthesis is enough to cause a fatal error. As you gain experience editing and programming macros you will learn how to identify your errors more easily.

You can save the macro even if it does not compile, but when you play it WordPerfect will try to compile it first, and you will receive the same error message(s). A macro must be successfully compiled before it can be played.

4.3 Comments

It is useful to include comments in your macro: you might want to explain how it works, what its purpose is, call attention to certain features, etc. Comments are a great help when editing a complex macro, particularly one that was programmed some time ago. Programming whose purpose and method seem obvious at the time when the macro was originally written can can be bewildering when looked at later. Comments appear as text within the macro when the macro is edited, but they are ignored when the macro is compiled.

To insert comments in a macro, precede the comment text with two forward slashes ("//"). When the macro is compiled everything from the two slashes to the end of the line will be ignored. Sometimes the compiler will not recognize comments unless there is a space after the two forward slashes, so it is safer to include a space; the space also makes the comment easier to read.




© 1999 Seth H. Katz
All rights reserved


E-MAIL TO AUTHOR


BACK Table of
Contents NEXT