WORDPERFECT MACRO TUTORIAL


7. Cursor Movement

7.1 Avoid using the arrow keys

Often you will want to have the macro move the cursor to a specific point. Remember that the macro will be running "blind," without "knowing" where the cursor is in a document, unless you tell it how and where to position the cursor. (Should you need to determine the current cursor position before the macro moves the cursor, this information can be obtained by accessing system variables).

Because macros often insert or delete text (and thus move the cursor) or will be played when the cursor is at different positions in a document, relative cursor positioning (up, down, left or right) often cannot be used, because the number of arrow keypresses necessary to position the cursor will vary. For this reason, the command equivalents to the arrow keys to position the cursor can be used only in limited circumstances. Most of the time, you will want the macro to position the cursor by moving by word, moving to the top or bottom of a document, to the beginning or end of a line, and especially by using "Find."

7.2 Using "Find" in a macro

In order to use Find in macros, you will need to know and understand its various features, especially how to find WordPerfect codes, and the various "actions" that Find can perform (select the match, position the cursor before or after the match, and extend a selection to and including the match).

The action that find performs is governed by the last find executed (the setting is "sticky"). You do not know what action will be in effect when the macro is run, and this action may or may not be the appropriate action for the Find in your macro. To ensure that the Find in your macro works as intended, you must specify the action the Find is to take. The commands to set the Find action are MatchSelection(), MatchPositionBefore, MatchPositionAfter(), and MatchExtendSelection.

Normally, if a Find fails in your macro (i.e., a match is not located), an error message will be displayed and the macro will end. Even if you actually want your macro to terminate at that point, generating an error message is not a graceful way to do it. You can trap the "not found" error and change what happens in your macro by using the ONNOTFOUND command.

7.3 Finding Codes

You probably know that to find codes in your document, you must insert them into the Find edit box by clicking on Match/Codes, and selecting the code(s) from the Codes dialog box. When you edit a macro that searches for a code, you will see text in the search string that looks like the tag for that code that is shown in the reveal codes window. However, that text in the macro is only a representation for display purposes.

If you open reveal codes while editing the macro, you will see that the "code" is really a "macro function." That is why you cannot simply type the code into the search string; you must insert it using the "codes" button on the macro toolbar. This will open the Macro Codes dialog, which you use to insert the "macro function" equivalent to the code you want to locate. Remember these codes include tabs, hard returns, and hard page breaks (i.e., anything not a character).

7.4 Program state

As we have seen, the position of the cursor can determine what happens when a macro is run. The same is true of "program state," which means the condition of the program at a particular time. For example, the results of playing a macro may vary depending on whether reveal codes is active, whether page view or draft view is active, whether hidden text is visible, etc. These differences should be kept in mind when recording and playing a macro. If the operation of a macro is dependent on a particular program condition being in effect when you run it, you should set that condition by including the applicable product command in the macro. If necessary, the macro can determine particulars of the current state of the program by accessing system variables.



© 1999 Seth H. Katz
All rights reserved


E-MAIL TO AUTHOR


BACK Table of
Contents NEXT