Chapter 19

FOR PROS ONLY: ADVANCED TOPICS

Even though WordPerfect is among the easier to use word processors for the IBM PC, the sheer number of features makes it a complex program to use. The same is true of its macro language. The macro programming environment is rich and varied, and even a book of this size cannot do justice to the entire language.

This chapter presents numerous topics for those familiar with WordPerfect's macro programming language (this chapter is not for those new to macros; if you haven't read the previous chapters in this book, you are urged to do so now before tackling this one). The chapter includes insights, tips, suggestions, and techniques you can use with your own macros. You'll learn about several nifty ways to implement menus in macros, how to write macros outside WordPerfect, how to generate macros automatically within WordPerfect, and lots more.

 

MENU SYSTEMS

You already know how to create single and multi-line menus using macros. You can even produce menus using the merge feature. The macro language lets you take the science of menu making even further, offering several methods of creating sophisticated "moving-bar" and "moving-arrow" menus. With some macro trickery, you can even create menu "engines" that are easily adaptable to any menu text you care to provide.


Horizontal Moving-Bar Menus

Lotus 1-2-3 popularized the horizontal moving-bar menu: along the top or bottom of the screen appears a single line of menu selections. One menu item is selected; you select another item by pressing the right or left cursor keys. When the menu item you want is highlighted, press the [Enter] key to select it.

A few ready-to-use macros -- appearing earlier in this book -- use a horizontal moving-bar approach to "point-and-shoot" selection of menu items. You can readily add moving-bar menus to your macro using the "engine" that follows. All you need to do is exchange the menu text for your own.

For obvious reasons, your menu items can't extend over one line. If you need to present more items than will fit on one line (in other words, your menu items consist of more than 79 characters), the best solution to divide them up among two or more separate lines, and use a multi-tiered menu approach.

In addition to using your own text for the menu, you need to modify the action {LABEL}s that appear at the end of the macro. You can include all of the commands to perform the action, or {NEST} or {CHAIN} to other macros.

Remember that the following macro should be treated as an engine, for the express purpose as a base for modification.


MOVEBAR1.WPM (provided on the Applications Disk)

{ON CANCEL}{GO}quit~~ 
{ASSIGN}#items~5~ 
{FOR}r~1~{VARIABLE}#items~~1~ 
{ASSIGN}{VARIABLE}r~r~~ 
{END FOR} 

{ASSIGN}item~1~ 
{ASSIGN}{VARIABLE}item~r~{^R}~ 
{CALL}prompt~ 

{ASSIGN}key~~ 
{LABEL}loop~ 
{LOOK}key~ 
{CASE}{VARIABLE}key~~ 
{Right}~right~ 
{Left}~left~ 
{Enter}~enter~ 
~ 
{GO}loop~ 

{LABEL}enter~ 
{GO}choice{VARIABLE}item~~ 
{LABEL}right~ 
{IF}{VARIABLE}item~={VARIABLE}#items~~ 
{GO}loop~ 
{END IF} 
{ASSIGN}{VARIABLE}item~r~~ 
{ASSIGN}item~{VARIABLE}item~+1~ 
{ASSIGN}{VARIABLE}item~r~{^R}~ 
{CALL}prompt~ 
{GO}loop~ 
{LABEL}left~ 
{IF}{VARIABLE}item~=1~ 
{GO}loop~ 
{END IF} 
{ASSIGN}{VARIABLE}item~r~~ 
{ASSIGN}item~{VARIABLE}item~-1~ 
{ASSIGN}{VARIABLE}item~r~{^R}~ 
{CALL}prompt~ 
{GO}loop~ 
{LABEL}prompt~ 
{PROMPT}{Home}{Del to EOL} 
{VARIABLE}1r~Reveal Codes {^S}  
{VARIABLE}2r~ Spell Document {^S}  
{VARIABLE}3r~ New Screen {^S}  
{VARIABLE}4r~ Switch Doc {^S}  
{VARIABLE}5r~ Quit WordPerfect {^S} 
~ 
{RETURN} 
{LABEL}choice1~ 
{Screen}{Screen} 
{Reveal Codes} 
{QUIT} 
{LABEL}choice2~ 
{Screen}{Screen} 
{Spell}D 
{QUIT} 
{LABEL}choice3~ 
{Exit}nn 
{QUIT} 
{LABEL}choice4~ 
{Switch} 
{QUIT} 
{LABEL}choice5~ 
{Exit}ny 
{QUIT} 
{LABEL}quit~ 
{Screen}{Screen} 
{QUIT}

The "prompt" routine contains the text for the menu line. You can remove items by deleting the entire line, including the {VARIABLE} command. To add more items, follow the syntax:

{VARIABLE}#r~Your message here {^S}

In place of the # character, use a unique number. The numbering should start at 1 for the first item, 2 for the second item, and so forth. You probably won't be able to fit more than five or six items on a single line.

The start of the macro includes an {ASSIGN} command where you should enter the total number of items in the menu. If there are six items, enter 6 for the {ASSIGN}#items~ statement.

A small modification of the MOVEBAR1.WPM macro presented above allows you to display a single line of menu options plus a second "help" line. This modification is shown in MOVEBAR2.WPM.


MOVEBAR2.WPM (provided on the Applications Disk)

{ON CANCEL}{GO}quit~~ 
{ASSIGN}#items~5~ 
{FOR}r~1~{VARIABLE}#items~~1~ 
{ASSIGN}{VARIABLE}r~r~~ 
{END FOR} 

{ASSIGN}item~1~ 
{ASSIGN}{VARIABLE}item~r~{^R}~ 
{CALL}prompt~ 
{CALL}2nd_line1~ 

{ASSIGN}key~~ 
{LABEL}loop~ 
{LOOK}key~ 
{CASE}{VARIABLE}key~~ 
{Right}~right~ 
{Left}~left~ 
{Enter}~enter~ 
~ 
{GO}loop~ 

{LABEL}enter~ 
{GO}choice{VARIABLE}item~~ 
{LABEL}right~ 
{IF}{VARIABLE}item~={VARIABLE}#items~~ 
{GO}loop~ 
{END IF} 
{ASSIGN}{VARIABLE}item~r~~ 
{ASSIGN}item~{VARIABLE}item~+1~ 
{ASSIGN}{VARIABLE}item~r~{^R}~ 
{CALL}prompt~ 
{CALL}2nd_line{VARIABLE}item~~ 
{GO}loop~ 
{LABEL}left~ 
{IF}{VARIABLE}item~=1~ 
{GO}loop~ 
{END IF} 
{ASSIGN}{VARIABLE}item~r~~ 
{ASSIGN}item~{VARIABLE}item~-1~ 
{ASSIGN}{VARIABLE}item~r~{^R}~ 
{CALL}prompt~ 
{CALL}2nd_line{VARIABLE}item~~ 
{GO}loop~ 
{LABEL}prompt~ 
{PROMPT}{Home}{Del to EOL} 
{VARIABLE}1r~Reveal Codes {^S}  
{VARIABLE}2r~ Spell Document {^S}  
{VARIABLE}3r~ New Screen {^S}  
{VARIABLE}4r~ Switch Doc {^S}  
{VARIABLE}5r~ Quit WordPerfect {^S} 
~ 
{RETURN} 
{LABEL}2nd_line1~ 
{PROMPT}{Home}{Down}{Del to EOL} 
Turn on Reveal Codes  ~ 
{RETURN} 
{LABEL}2nd_line2~ 
{PROMPT}{Home}{Down}{Del to EOL} 
Spell check this document  ~ 
{RETURN} 
{LABEL}2nd_line3~ 
{PROMPT}{Home}{Down}{Del to EOL} 
Clear the screen for a new document  ~ 
{RETURN} 
{LABEL}2nd_line4~ 
{PROMPT}{Home}{Down}{Del to EOL} 
Switch to the alternate document  ~ 
{RETURN} 
{LABEL}2nd_line5~ 
{PROMPT}{Home}{Down}{Del to EOL} 
Leave WordPerfect  ~ 
{RETURN} 
{LABEL}choice1~ 
{Screen}{Screen} 
{Reveal Codes} 
{QUIT} 
{LABEL}choice2~ 
{Screen}{Screen} 
{Spell}D 
{QUIT} 
{LABEL}choice3~ 
{Exit}nn 
{QUIT} 
{LABEL}choice4~ 
{Switch} 
{QUIT} 
{LABEL}choice5~ 
{Exit}ny 
{QUIT} 
{LABEL}quit~ 
{Screen}{Screen} 
{QUIT}

The main enhancement to MOVEBAR2.WPM is the addition of {CALL} commands to the 2nd line prompts. Each 2nd line prompt is provided in it's own label. As the macro displays a new highlight for the menu, it updates the message shown on the second line.


Vertical Moving Bar Menus

The vertical moving bar menu is similar to the type used in WordPerfect's pull-down menus. Displayed is a list of menu items, with one of the items selected (usually highlighted or set in reverse video). You use the up and down arrow keys to highlight other items, then press the [Enter] key to select the one you want.

Here's a method you can use to present up to 16 items in a single menu (you can modify the macro to present up to 24 items, if you wish). The MEN1.WPM macro that follows was constructed so that it could be readily modified with your own menu items.


MEN1.WPM (provided on the Applications Disk)

{ON CANCEL}{GO}cancel~~ 
{ASSIGN}0~1~ 
{ASSIGN}2~~ 
{ASSIGN}3~16~  {;}Total menu items~ 

{PROMPT}{Del to EOP}~    {;}Clear screen or pop-up box~ 
{CALL}call_rows~ 
{ASSIGN}2~{^R}~ 
{CALL}row_1~ 

{LABEL}check_keys~ 
{ASSIGN}1~~ 
{LABEL}loop~ 
{LOOK}1~ 
{CASE}{VAR 1}~ 
{Up}~up~ 
{Down}~down~ 
{Enter}~enter~ 
{Home}~home~ 
{End}~end~ 
~ 
{GO}loop~ 

{LABEL}enter~ 
{DISPLAY OFF} 
{DISPLAY ON} 
{CHAIN}MACRO{VAR 0}~{;}Macro file prefix~ 
{RETURN} 
{LABEL}up~ 
{ASSIGN}2~~ 
{CALL}row_{VAR 0}~ 
{ASSIGN}0~{VAR 0}-1~ 
{IF}{VAR 0}<1~ 
{ASSIGN}0~{VAR 3}~ 
{END IF} 
{ASSIGN}2~{^R}~ 
{CALL}row_{VAR 0}~ 
{GO}loop~ 
{LABEL}down~ 
{ASSIGN}2~~ 
{CALL}row_{VAR 0}~ 
{ASSIGN}0~{VAR 0}+1~ 
{IF}{VAR 0}>{VAR 3}~ 
{ASSIGN}0~1~ 
{END IF}
{ASSIGN}2~{^R}~ 
{CALL}row_{VAR 0}~ 
{GO}loop~ 
{LABEL}home~ 
{ASSIGN}2~~ 
{CALL}row_{VAR 0}~ 
{ASSIGN}0~1~ 
{ASSIGN}2~{^R}~ 
{CALL}row_{VAR 0}~ 
{GO}loop~ 
{LABEL}end~ 
{ASSIGN}2~~ 
{CALL}row_{VAR 0}~ 
{ASSIGN}0~{VAR 3}~ 
{ASSIGN}2~{^R}~ 
{CALL}row_{VAR 0}~ 
{GO}loop~ 
{LABEL}row_1~  {;}Menu items (rows 1 through nn)~ 
{PROMPT}{^P} 
{VAR 2}Row 1        {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_2~ 
{PROMPT}{^P} 
{VAR 2}Row 2        {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_3~ 
{PROMPT}{^P} 
{VAR 2}Row 3        {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_4~ 
{PROMPT}{^P} 
{VAR 2}Row 4        {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_5~ 
{PROMPT}{^P} 
{VAR 2}Row 5        {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_6~ 
{PROMPT}{^P} 
{VAR 2}Row 6        {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_7~ 
{PROMPT}{^P} 
{VAR 2}Row 7        {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_8~ 
{PROMPT}{^P} 
{VAR 2}Row 8        {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_9~ 
{PROMPT}{^P} 
{VAR 2}Row 9        {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_10~ 
{PROMPT}{^P} 
{VAR 2}Row 10       {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_11~ 
{PROMPT}{^P} 
{VAR 2}Row 11       {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_12~ 
{PROMPT}{^P} 
{VAR 2}Row 12       {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_13~ 
{PROMPT}{^P} 
{VAR 2}Row 13       {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_14~ 
{PROMPT}{^P} 
{VAR 2}Row 14       {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_15~ 
{PROMPT}{^P} 
{VAR 2}Row 15       {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}row_16~ 
{PROMPT}{^P} 
{VAR 2}Row 16       {^S}{Enter}{Up}~ 
{RETURN} 
{LABEL}call_rows~   {;}Row display; add {RETURN} after last menu line
used~ 
{CALL}row_1~ 
{CALL}row_2~ 
{CALL}row_3~ 
{CALL}row_4~ 
{CALL}row_5~ 
{CALL}row_6~ 
{CALL}row_7~ 
{CALL}row_8~ 
{CALL}row_9~ 
{CALL}row_10~ 
{CALL}row_11~ 
{CALL}row_12~ 
{CALL}row_13~ 
{CALL}row_14~ 
{CALL}row_15~ 
{CALL}row_16~ 
{RETURN} 

{LABEL}cancel~ 
{DISPLAY OFF}{DISPLAY ON} 
{QUIT}

Comments are provided as an aid in modifying the macro. Here's how to modify this macro for your own applications.

  1. Indicate the total number of menu items for variable 3. The example macro uses the full complement of 16 items.
  2. In this macro, the menu items {CHAIN} to other macros. The {CHAIN}MACRO{VAR 0} command in the "Enter" routine runs {CHAIN}ed macros with the names MACRO1.WPM, MACRO2.WPM, MACRO3.WPM, and so forth. The numbers correspond to the item number in the menu (MACRO3.WPM is item 3 in the menu, etc.). You can use any macro file prefix you want. You can also modify the menu engine so that it {NEST}s to the macros instead, or {GO}s or {CALL}s other routines within the menu macro.
  3. The "row_x" routines are the actual menu items. For consistency, each item should be the same length, with extra blank spaces to pad out the difference.
  4. Add a {RETURN} command after the last menu item you use, as indicated in the comment for the "call_rows" routine. For example, if your menu macro uses items 1 through 11, add a {RETURN} after the {CALL}row_11~ statement.

The MEN1.WPM macro doesn't place the menu items in a box. If you'd like to use a box frame, add a "box" routine at the end, and {CALL} it at the beginning of the macro. Make sure your box -- constructed as explained in Chapter 18, "Macro Strategies," is wide and long enough to enclose all the menu items. Alternatively, you can use the box making macro, detailed later in this chapter in the "Macro Tools" section, as an aid in making menu frames.

In addition, you can provide {^P} cursor positioning coordinates before the box and menu items, if you wish, to place your moving-bar menu anywhere on the screen.

IMPORTANT NOTE: Although MEN1.WPM is designed so that it taxes WordPerfect only minimally, the menu may appear sluggish when run on a slow computer. Generally, the faster the computer, the more nimble the macro will appear. You obtain best results if the computer is an AT-class or better, running at 10 MHz or faster. You can minimize the sluggishness inherent in slower computers by minimizing the number of menu items, and restricting the length of each item to under 20 characters.

 

A far more sophisticated vertical moving bar macro is provided in MEN2.WPM, included on the Applications Disk. It operates in the same basic manner, but presents a small scrollable "box" of menus. MEN2.WPM lets you include up to 40 menu items, even though you only see a portion of them at a time. As you press the up and down cursor keys, new menu items scroll into the box. Use the Page Up] and [Page Down] keys to quickly scroll through the items.

The MEN2.WPM macro (which, because of its size, won't be detailed here), includes a pop-up box. If your menu items won't fit in the width of the box, you can increase the size of the frame. As with MEN1.WPM, however, you should limit the width of menu items to avoid sluggishness in the execution of the macro.


Moving-Arrow Menus

The highlight bar in moving-bar menus slows down execution of the macro. You can speed up your menu macros by using a pointing arrow instead of the highlight bar. MAKEBOX1.WPM, as follows, shows you how.

To modify MAKEBOX1.WPM, provide the dimensions of the menu box in the wide and high variables (these are assigned at the very beginning of the macro. In addition, provide coordinates for the box using the col (for column) and row variables. For example, to place the menu box so that its upper left corner is at column 18 and row 7, enter 18 for col and 7 for row.

Indicate the menu items using the syntax:

{ASSIGN}item#~Menu item goes here~

In place of the # character, enter a unique item number. You should not have more items than will fit in the menu box. As shown in the example macro, the box is eight lines high; and there are eight menu items.

The MAKEBOX1.WPM lets you add an optional menu title. This title appears at the top of the box. The title is assigned to the title variable. Bold attributes are added to make the title stand out.


MAKEBOX1.WPM (provided on the Applications Disk)

{ASSIGN}wide~17~ 
{ASSIGN}high~8~ 
{ASSIGN}col~18~ 
{ASSIGN}row~7~ 
{ASSIGN}line1~This is line A~ 
{ASSIGN}line2~This is line B~ 
{ASSIGN}line3~This is line C~ 
{ASSIGN}line4~This is line D~ 
{ASSIGN}line5~This is line E~ 
{ASSIGN}line6~This is line F~ 
{ASSIGN}line7~This is line G~ 
{ASSIGN}line8~This is line H~ 
{ASSIGN}label~{^]}Test Box{^\}~ 

{CALL}make_box~ 
{GO}pointer~ 
{QUIT} 

{LABEL}make_box~ 
{ON CANCEL}{GO}exit~~ 
{ASSIGN}space~ ~ 
{FOR}sp_count~1~{VARIABLE}wide~~1~ 
{ASSIGN}space~{VARIABLE}space~ ~ 
{END FOR} 
{ASSIGN}bar~~ 
{FOR}top_bot~1~{VARIABLE}wide~~1~ 
{ASSIGN}bar~{VARIABLE}bar~~ 
{END FOR} 
{PROMPT}{^P}{NTOK}{VARIABLE}col~~{NTOK}{VARIABLE}row~~ 
{VARIABLE}bar~~ 
{ASSIGN}high~{VARIABLE}high~+1~ 
{FOR}height~1~{VARIABLE}high~~1~ 
{ASSIGN}mid~{VARIABLE}height~+{VARIABLE}row~~ 
{PROMPT}{^P}{NTOK}{VARIABLE}col~~{NTOK}
{VARIABLE}mid~~ {VARIABLE}space~~ 
{END FOR} 
{PROMPT}{^P}{NTOK}{VARIABLE}col~~{NTOK}{VARIABLE}mid~~
{VARIABLE}bar~~ 
{LABEL}make_text~ 
{ASSIGN}text_col~{VARIABLE}col~+3~ 
{ASSIGN}text_row~{VARIABLE}row~+1~ 
{ASSIGN}text_end~{VARIABLE}high~+{VARIABLE}row~-1~ 
{FOR}line_n~1~{VARIABLE}high~-1~1~ 
{ASSIGN}text~{VARIABLE}line{VARIABLE}line_n~~~ 
{PROMPT}{^P}{NTOK}{VARIABLE}text_col~~ 
{NTOK}{VARIABLE}text_row~~ 
{VARIABLE}text~{Enter}~ 
{ASSIGN}text_row~{VARIABLE}text_row~+1~ 
{END FOR} 
{ASSIGN}lab_col~{VARIABLE}col~+1~ 
{PROMPT}{^P}{NTOK}{VARIABLE}lab_col~~ 
{NTOK}{VARIABLE}row~~{VARIABLE}label~~ 
{RETURN} 

{LABEL}pointer~ 
{ON CANCEL}{GO}exit~~ 
{ASSIGN}c_pos~{VARIABLE}col~+1~ 
{ASSIGN}r_pos~{VARIABLE}row~+1~ 
{ASSIGN}arrow~~ 
{ASSIGN}no_arrow~  ~ 
{PROMPT}{^P}{NTOK}{VARIABLE}c_pos~~
{NTOK}{VARIABLE}r_pos~~{VARIABLE}arrow~~ 
{ASSIGN}key~~ 
{LABEL}loop~ 
{LOOK}key~ 
{CASE}{VARIABLE}key~~ 
{Up}~up~ 
{Down}~down~ 
{Page Up}~home~ 
{Page Down}~end~ 
{Screen Up}~home~ 
{Screen Down}~end~ 
{Left}~up~ 
{Right}~down~ 
{Home}~home~ 
{End}~end~ 
{Enter}~enter~ 
{Exit}~exit~ 
{Cancel}~exit~ 
~ 
{GO}loop~ 

{LABEL}up~ 
{IF}{VARIABLE}r_pos~<{VARIABLE}row~+2~ 
{ASSIGN}r_pos~{VARIABLE}row~+1~ 
{ELSE} 
{CALL}erase_arrow~ 
{ASSIGN}r_pos~{VARIABLE}r_pos~-1~ 
{CALL}write_arrow~ 
{END IF} 
{GO}loop~ 
{LABEL}down~ 
{IF}{VARIABLE}r_pos~>{VARIABLE}text_end~-1~ 
{ASSIGN}r_pos~{VARIABLE}text_end~~ 
{ELSE} 
{CALL}erase_arrow~ 
{ASSIGN}r_pos~{VARIABLE}r_pos~+1~ 
{CALL}write_arrow~ 
{END IF} 
{GO}loop~ 
{LABEL}home~ 
{CALL}erase_arrow~ 
{ASSIGN}r_pos~{VARIABLE}row~+1~ 
{CALL}write_arrow~ 
{GO}loop~ 
{LABEL}end~ 
{CALL}erase_arrow~ 
{ASSIGN}r_pos~{VARIABLE}text_end~~ 
{CALL}write_arrow~ 
{GO}loop~ 
{LABEL}enter~ 
{ASSIGN}item~{VARIABLE}r_pos~-{VARIABLE}row~~ 
{DISPLAY OFF}{DISPLAY ON} 
{CHAIN}macro{VARIABLE}item~~ 
{RETURN} 
{LABEL}exit~ 
{DISPLAY OFF}{DISPLAY ON} 
{QUIT} 
{LABEL}write_arrow~ 
{PROMPT}{^P}{NTOK}{VARIABLE}c_pos~~
{NTOK}{VARIABLE}r_pos~~{VARIABLE}arrow~~ 
{RETURN} 
{LABEL}erase_arrow~ 
{PROMPT}{^P}{NTOK}{VARIABLE}c_pos~~
{NTOK}{VARIABLE}r_pos~~{VARIABLE}no_arrow~~ 
{RETURN} 

Use the cursor keys to move the selector arrow up and down. The {CASE} structure indicates all of the keys that can be used.

Pressing [Enter] selects the menu items that is currently selected. The macro {CHAIN}s to a numbered macro. The example MAKEBOX1.WPM macro uses the macro prefix "MACRO" (for macros named MACRO1.WPM, MACRO2.WPM, MACRO3.WPM, etc.), but you can change the prefix if you like. The prefix should not be more than six characters, so that you can {CHAIN} to double-digit (that is "MACRO21.WPM") macros.

If you prefer, you can edit the "Enter" routine so that you {NEST}, {GO}, or {CALL} another macro or routine. Chaining is used because it allows you to more easily build complex menu macros using independent (and therefore easier to "debug") macro files.

If your computer is at least AT-class (80286 microprocessor) running at 12 MHz or faster, you may want to try MAKEBOX2.WPM, also provided on the Applications Disk. This macro functions the same as MAKEBOX1.WPM, but automatically sizes the menu box to fit the length and number of menu items you've written.

 

MACRO TOOLS

The carpenter can work faster and better with the proper tools. As a WordPerfect macro programmer, you can improve and increase your output with macro tools. The MACTOOLS.WPK keyboard layout, included on the Applications Disk, provides seven macro tools you can use to make the process of authoring macro easier and less error-prone. Feel free to create and add your own special tools as you see fit.

The MACTOOLS.WPK keyboard layout consists of the following Alt-letter macros:

 

Alt-P -- {^P} Position Calculator

The {^P} position calculator automatically calculates the proper column and row coordinate codes to use with the {^P} cursor attribute. At the prompts, enter the column and row coordinates; the macro will convert these to the proper codes. Note that you can enter 0 for either or both the column and row. The macro will insert the {Compose} code, which WordPerfect interprets as column/row 0. The macro automatically inserts the {^P} code as well, so you don't have to do it.

You can use the Alt-P macro only within the macro and keyboard layout editing windows.


Alt-K -- On-the-Fly KTON Converter

This macro converts any keypress to its WordPerfect numeric equivalent. For example, pressing the letter A returns a 65. You can press any key or key combination on the keyboard except those keys that have been remapped as macros.

You can use the Alt-K macro anywhere within WordPerfect.


Alt-L -- Variable Contents Lister

Use the Alt-L macro whenever you need to print the contents of a numbered or named variable. At the prompt, enter the number or variable name, then press [Enter]. The contents of the variable is printed in the document or within the macro editor.

You can use Alt-L anywhere within WordPerfect.


Alt-C -- Common Constructs

The Alt-C macro lets you enter common macro fragments, including {IF}, {FOR}, and {WHILE} instructions. At the prompt select a construct to use.

 

Alt-V -- Variable Contents Prompter

The Alt-V macro is similar to Alt-L, except that the contents of the variable is displayed in a prompt at the bottom of the screen. The contents are not printed in the document or macro window.

You can use the Alt-V macro anywhere within WordPerfect.


Alt-B -- Macro Box Maker

Use the Alt-B macro to make boxes within the macro or keyboard layout windows. At the prompt, provide the width and height of the box. Specify internal or external dimensions, and indicate if you want to include {^P} cursor coordinates. If you answer Yes, enter the starting column and row coordinates. The boxmaker macro then completes the box for you.

Note that the Alt-B macro requires extra memory to run properly. If the macro stops without making a box, you may need to free up more memory. Try clearing the document screens, or use WordPerfect without Shell.

The Alt-B macro can be used only in the macro and keyboard layout windows.


Alt-N -- On-the-Fly NTOK Converter

Alt-N converts numbers to their WordPerfect key equivalents. For example, entering 65 returns the letter A. See Appendix E for a list of WordPerfect key numbers. The macro will execute editing and cursor movement keys, not not print their codes in the macro window.

 

MACRO FILE FORMAT

WordPerfect macro files follow a unique and predictable format. Understanding this format allows you to experiment with advanced macro techniques, resurrect macros (using a byte-editor) that have been lost or damaged, and even create macros from scratch outside WordPerfect, using a programming language such as BASIC or C.

The macro file format follows this overall construction:

Here's a more complete rundown (starting at byte 1 for the very beginning of the file).

  1. Byte 1. ASCII 255.
  2. Bytes 2, and 4: ASCII characters WPC.
  3. Byte 5: macro code starting byte. This is normally the ASCII character 9, which represents decimal 57. Byte 57 is the standard starting address (where the macro code actually starts) if you haven't provided a description for the macro.
  4. Bytes 6, 7, 8: ASCII 0.
  5. Bytes 9, 10, 11, and 12: ASCII 1.
  6. Bytes 13, 14, 15, 16: ASCII 0.
  7. Byte 17: ASCII 251.
  8. Byte 18: ASCII 255.
  9. Byte 19: ASCII 5.
  10. Byte 20: ASCII 0.
  11. Byte 21: ASCII 40.
  12. Bytes 22 through 26: ASCII 0.
  13. Byte 27: ASCII 1.
  14. Byte 28: ASCII 0.
  15. Byte 29: Secondary macro starting address. This address is normally ASCII 1 if you haven't provided a description for the macro.
  16. Byte 30, 31, and 32: ASCII 0.
  17. Byte 33: ASCII 56 (character 8).
  18. Bytes 34 through 56: ASCII 0.
  19. Byte 57: Start of macro or description.

Note: The format for WordPerfect 5.0 macros are identical to those in 5.1 (described above) except for bytes 11 and 12. In WordPerfect 5.0, these are ASCII 0.

The actual macro code consists of two characters: a high-order and low-order byte. The low-order byte identifies the type of code; the high-order byte identifies the actual code used. For example, all macro commands use a low-order byte of ASCII 252. The {ASSIGN} command uses a high-order byte of ASCII 1, the {BELL} command ASCII 2, and so forth. For the first two macro commands, their bytes -- as viewed in a macro file -- would appear as:

1    252  (for {ASSIGN})
2    252  (for {BELL})

By the same token, alphanumeric characters (the letter A, for instance), are coded by their WordPerfect character set number. The letter A is coded

65   0 

-- character 65 in set 0. The high-order byte is the character number; the low-order byte is the character set number. The {VAR x}, {ALT x}, and other macro codes use a similar construction. Appendix E lists the high- and low-order byte codes. The codes are listed in ASCII and hex format.

WordPerfect knows that the macro is finished when it encounters a double zero code, 0 0. The double zero is WordPerfect's stop code for macros.

Tip: The construction of macros reveals the secret of their size. Because all macros contain the same basic header, the minimum file size for a macro is 57 bytes. The description takes up one byte for every character, up to a maximum of 39 characters. Therefore, an empty macro -- except for a 39 character description -- is 96 bytes (57 bytes for the header and 39 bytes for the description). Every macro code, including alphanumeric characters, consume two bytes. The same 96 byte macro filled with 100 characters (macro commands, codes, character, and so forth), is 296 bytes long. The stop code (0 0) is not included in the size of the macro.

All WordPerfect 5.1 macros share the same header with the exception of two bytes: at locations 5 and 29. The character at byte 5 indicates the start (or offset) of the macro code from the absolute beginning of the macro file, or byte 1. If you haven't provided a description, the macro code starts at byte 57. Conversely, a if you write a 10-character description, the offset is 67, and so forth. The offset is represented by an ASCII character. The ASCII character for decimal 57 is 9, the ASCII character for decimal 67 is C, etc. The offset at byte 29 indicates the start of the macro code relative to the start of the description, if any.

WordPerfect recognizes a properly created macro file by its header and by its two-character sequence of high- and low-order bytes for each command, code, and character. If your macro file deviates from this accepted standard, WordPerfect will refuse to recognize it, or the macro may operate unpredictably. For example, disrupting the sequence of high- and low-order bytes causes the macro code to display gibberish in the macro editor window. This macro probably wouldn't even run, but if it did, its action would be entirely unpredictable.

 

MACRO GENERATION

There are several approaches to automatically generating macros, including using other macros or any of one several programming languages, such as BASIC or C. The benefit of such "auto-generation" is that you can construct a universal macro or program that can automatically create a customized macro. For example, it's a fairly easy matter to create an auto-generation macro that prompts for a name and address, then builds a customized letterhead macro designed for use with PostScript printers.

Detailed here are three ways to approach the issue of automatic macro generation.


Using Macros

The most straightforward way of automatically making macros is to use another macro. The generating macro includes the basic commands and text you want included in the custom macro. In addition, the generating macro incorporates one or more prompts for entering a name, address, or other variable data. The user's response is then inserted into the custom macro.

WordPerfect does its best to prevent you from creating a macro using another macro, but there is a little-known "backdoor" approach, using the keyboard layout map menu.

The following macro, named AUTOGEN.WPM, creates a sample customized macro called "TESTMAC.WPM." It allows you to enter your name and address. It then inserts several codes. The finished customized macro isn't very useful, but it's provided to show you how the technique works.


AUTOGEN.WPM (provided on the Applications Disk)

{TEXT}name~What is your name?  ~ 
{TEXT}add~What is your address?  ~ 

{DISPLAY OFF} 
{Setup}KCtemp####{Enter} 
MM{Delete} 

{^V}{BELL}{Enter} 
{^V}{ASSIGN}1~1000~{Enter} 
{VARIABLE}name~{Enter} 
{VARIABLE}add~{Enter} 
{^V}{Enter} 
{^V}{PAUSE}{Enter} 
 
{Exit}{Exit} 
ES 
testmac{Enter} 
{IF}{STATE}&1024~ 
y 
{END IF} 
{Exit}DY{Exit} 
{CHAR}key~ 
Sample auto-generated macro complete.  Press a key  ~ 
{Screen}{Screen}

Note that commands that are to be inserted into the macro are preceded by a {^V} code. If you want to insert a commenting Enter or Tab into the customized macro, provide an {Enter} or {Tab} code without {^V}. Adding the {^V} code causes the actual {Enter} and {Tab} codes to be inserted into the customized macro. Chapter 18, "Macro Strategies," discusses the technique of inserting macro codes into other macros.

The AUTOGEN.WPM macro creates a temporary keyboard layout named TEMP####.WPK. This layout is never activated, but used as a means to prepare the customized macro. After AUTOGEN.WPM is finished, the TEMP####.WPK file is deleted.

The working part of the macro is the segment:

{Setup}KCtemp####{Enter} 
MM{Delete} 

This creates a new keyboard layout named TEMP####.WPK, then accesses a key using the Map feature. The macro is then built inside the keyboard layout editing window. When all the macro code is inserted (as if you entered it yourself directly from the keyboard), the generating macro then exits the editing window, saves the macro under the name TESTMAC.WPM, and deletes the TEMP####.WPK layout.

{Exit}{Exit} 
ES 
testmac{Enter} 
{IF}{STATE}&1024~ 
y 
{END IF} 
{Exit}DY{Exit} 

You can modify AUTOGEN.WPM by providing your own prompts at the beginning. The contents of the example TESTMAC.WPM macro is defined with the code:

{^V}{BELL}{Enter} 
{^V}{ASSIGN}1~1000~{Enter} 
{VARIABLE}name~{Enter} 
{VARIABLE}add~{Enter} 
{^V}{Enter} 
{^V}{PAUSE}{Enter} 

Change this code to suit your requirements.


Using BASIC

BASIC (or another programming language such as C, Assembler, or Pascal) can also be used to generate customized macros. Your program must not only furnish the require header needed by WordPerfect, but enter the macro commands, codes, and text in the appropriate format (see the section "Macro File Format," earlier in this chapter, for a discussion on the organization and content of macro files).

Included on the Applications Disk is MAKEMAC.BAS, a program written in QuickBASIC, for versions 4.0 or later (and ready for compiling, if you desire). The program uses string variables to assign the various WordPerfect macro commands and codes to their high- and low-order byte formats. It then opens a new file and builds the header in the proper format. Your customizing code then inserts those commands and text you want in the finished macro.

An example of a macro-generating BASIC program is provided in SAMPLE.BAS

SAMPLE.BAS (provided on the Applications Disk)

assign$ = CHR$(1) + CHR$(252)
bell$ = CHR$(2) + CHR$(252)
break$ = CHR$(3) + CHR$(252)
call$ = CHR$(4) + CHR$(252)
canOff$ = CHR$(5) + CHR$(252)
canOf$ = CHR$(6) + CHR$(252)
case$ = CHR$(7) + CHR$(252)
casecall$ = CHR$(8) + CHR$(252)
chain$ = CHR$(9) + CHR$(252)
char$ = CHR$(10) + CHR$(252)
comment$ = CHR$(11) + CHR$(252)
disOff$ = CHR$(12) + CHR$(252)
disOn$ = CHR$(13) + CHR$(252)
else$ = CHR$(14) + CHR$(252)
endfor$ = CHR$(15) + CHR$(252)
endif$ = CHR$(16) + CHR$(252)
endwhile$ = CHR$(17) + CHR$(252)
for$ = CHR$(18) + CHR$(252)
foreach$ = CHR$(19) + CHR$(252)
go$ = CHR$(20) + CHR$(252)
if$ = CHR$(21) + CHR$(252)
label$ = CHR$(22) + CHR$(252)
look$ = CHR$(23) + CHR$(252)
nest$ = CHR$(24) + CHR$(252)
next$ = CHR$(25) + CHR$(252)
shell$ = CHR$(26) + CHR$(252)
onCan$ = CHR$(27) + CHR$(252)
onErr$ = CHR$(28) + CHR$(252)
onFnd$ = CHR$(29) + CHR$(252)
pause$ = CHR$(30) + CHR$(252)
prompt$ = CHR$(31) + CHR$(252)
quit$ = CHR$(32) + CHR$(252)
restart$ = CHR$(33) + CHR$(252)
return$ = CHR$(34) + CHR$(252)
retCan$ = CHR$(35) + CHR$(252)
retErr$ = CHR$(36) + CHR$(252)
retFnd$ = CHR$(37) + CHR$(252)
speed$ = CHR$(38) + CHR$(252)
stepOn$ = CHR$(39) + CHR$(252)
text$ = CHR$(40) + CHR$(252)
state$ = CHR$(41) + CHR$(252)
wait$ = CHR$(42) + CHR$(252)
while$ = CHR$(43) + CHR$(252)
macCom$ = CHR$(44) + CHR$(252)
stepOff$ = CHR$(45) + CHR$(252) origKey$ = CHR$(46) + CHR$(252)
ifExist$ = CHR$(47) + CHR$(252)
menuOff$ = CHR$(48) + CHR$(252)
menuOn$ = CHR$(49) + CHR$(252)
status$ = CHR$(50) + CHR$(252)
inp$ = CHR$(51) + CHR$(252)
var$ = CHR$(52) + CHR$(252)
system$ = CHR$(53) + CHR$(252)
menuOn$ = CHR$(50) + CHR$(252)
middle$ = CHR$(54) + CHR$(252)
ntok$ = CHR$(55) + CHR$(252)
kton$ = CHR$(56) + CHR$(252)
len$ = CHR$(57) + CHR$(252)
hTilde$ = CHR$(58) + CHR$(252)

a$ = CHR$(1) + CHR$(128)
b$ = CHR$(2) + CHR$(128)
c$ = CHR$(3) + CHR$(128)
d$ = CHR$(4) + CHR$(128)
e$ = CHR$(5) + CHR$(128)
f$ = CHR$(6) + CHR$(128)
g$ = CHR$(7) + CHR$(128)
home$ = CHR$(8) + CHR$(128)
tab$ = CHR$(9) + CHR$(128)
enter$ = CHR$(10) + CHR$(128)
delEOL$ = CHR$(11) + CHR$(128)
delEOP$ = CHR$(12) + CHR$(128)
m$ = CHR$(13) + CHR$(128)
n$ = CHR$(14) + CHR$(128)
o$ = CHR$(15) + CHR$(128)
p$ = CHR$(16) + CHR$(128)
q$ = CHR$(17) + CHR$(128)
r$ = CHR$(18) + CHR$(128)
s$ = CHR$(19) + CHR$(128)
t$ = CHR$(20) + CHR$(128)
u$ = CHR$(21) + CHR$(128)
v$ = CHR$(22) + CHR$(128)
up$ = CHR$(23) + CHR$(128)
rt$ = CHR$(24) + CHR$(128)
lt$ = CHR$(25) + CHR$(128)
dn$ = CHR$(26) + CHR$(128)
esc$ = CHR$(27) + CHR$(128)
bkSlash$ = CHR$(28) + CHR$(128)
clBracket$ = CHR$(29) + CHR$(128)
clKeybd$ = CHR$(30) + CHR$(128)
clUline$ = CHR$(31) + CHR$(128)
cancel$ = CHR$(32) + CHR$(128)
search$ = CHR$(33) + CHR$(128)
help$ = CHR$(34) + CHR$(128)
indent$ = CHR$(35) + CHR$(128)
list$ = CHR$(36) + CHR$(128)
bold$ = CHR$(37) + CHR$(128) exit$ = CHR$(39) + CHR$(128)
underline$ = CHR$(40) + CHR$(128)
endField$ = CHR$(40) + CHR$(128)
save$ = CHR$(41) + CHR$(128)
setup$ = CHR$(44) + CHR$(128)
ltSearch$ = CHR$(45) + CHR$(128)
switch$ = CHR$(46) + CHR$(128)
lrIndent$ = CHR$(47) + CHR$(128)
dateOutline$ = CHR$(48) + CHR$(128)
center$ = CHR$(49) + CHR$(128)
print$ = CHR$(50) + CHR$(128)
format$ = CHR$(51) + CHR$(128)
mergeCode$ = CHR$(52) + CHR$(128)
retrieve$ = CHR$(53) + CHR$(128)
thesaurus$ = CHR$(56) + CHR$(128)
replace$ = CHR$(57) + CHR$(128)
reveal$ = CHR$(58) + CHR$(128)
block$ = CHR$(59) + CHR$(128)
mark$ = CHR$(60) + CHR$(128)
flRight$ = CHR$(61) + CHR$(128)
colTable$ = CHR$(62) + CHR$(128)
style$ = CHR$(63) + CHR$(128)
graphics$ = CHR$(64) + CHR$(128)
macro$ = CHR$(65) + CHR$(128)
shellOut$ = CHR$(68) + CHR$(128)
spell$ = CHR$(69) + CHR$(128)
screen$ = CHR$(70) + CHR$(128)
move$ = CHR$(71) + CHR$(128)
textInOut$ = CHR$(72) + CHR$(128)
tabAlign$ = CHR$(73) + CHR$(128)
footnote$ = CHR$(74) + CHR$(128)
font$ = CHR$(75) + CHR$(128)
merge$ = CHR$(76) + CHR$(128)
backspace$ = CHR$(80) + CHR$(128)
delete$ = CHR$(81) + CHR$(128)
delWord$ = CHR$(82) + CHR$(128)
wordRight$ = CHR$(83) + CHR$(128)
wordLeft$ = CHR$(84) + CHR$(128)
end$ = CHR$(85) + CHR$(128)
goto$ = CHR$(88) + CHR$(128)
pageUp$ = CHR$(89) + CHR$(128)
pageDown$ = CHR$(90) + CHR$(128)
screenDown$ = CHR$(91) + CHR$(128)
screenUp$ = CHR$(92) + CHR$(128)
typeover$ = CHR$(93) + CHR$(128)
marginRel$ = CHR$(84) + CHR$(128)
hpg$ = CHR$(85) + CHR$(128)
shy$ = CHR$(86) + CHR$(128)
paraUp$ = CHR$(99) + CHR$(128)
paraDown$ = CHR$(100) + CHR$(128)
itemLeft$ = CHR$(101) + CHR$(128)
itemRight$ = CHR$(102) + CHR$(128) itemUp$ = CHR$(103) + CHR$(128)
ItemDown$ = CHR$(104) + CHR$(128)
altHome$ = CHR$(105) + CHR$(128)
menuBar$ = CHR$(107) + CHR$(128)
bkAppend$ = CHR$(108) + CHR$(128)
bkMove$ = CHR$(109) + CHR$(128)
bkCopy$ = CHR$(110) + CHR$(128)

var0$ = CHR$(0) + CHR$(255)
var1$ = CHR$(1) + CHR$(255)
var2$ = CHR$(2) + CHR$(255)
var3$ = CHR$(3) + CHR$(255)
var4$ = CHR$(4) + CHR$(255)
var5$ = CHR$(5) + CHR$(255)
var6$ = CHR$(6) + CHR$(255)
var7$ = CHR$(7) + CHR$(255)
var8$ = CHR$(8) + CHR$(255)
var9$ = CHR$(9) + CHR$(255)
alt$ = CHR$(254)

emEnter$ = CHR$(10) + CHR$(0)
emTab$ = CHR$(9) + CHR$(0)


start:
CLS
INPUT "Name of the new macro file "; filename$
OPEN filename$ FOR OUTPUT AS #1
FOR readData = 1 TO 57
   READ X
   PRINT #1, CHR$(X);
NEXT readData

macroData:
PRINT #1, text$;
   prText$ = "key~Please enter your name  ~"
   GOSUB doText
PRINT #1, newString$; emEnter$;


closeUp:
PRINT #1, CHR$(0); CHR$(0);
CLOSE #1
END


doText:
newString$ = ""
FOR char = 1 TO LEN(prText$)
   newString$ = newString$ + MID$(prText$, char, 1)
   newString$ = newString$ + CHR$(0)
NEXT char RETURN


DATA 255,87,80,67,57,0,0,0,1,1,1,1,0,0,0,0,251,255,4,0,40
DATA 0,0,0,0,0,1,0,1,0,0,0,56,0,0,0,0,0,0,0,0,0,0,0,0,0,0
DATA 0,0,0,0,0,0,0,0,0,0

Your customizing code is entered under the macroData: label. To enter any macro command or code, enter PRINT #1 and the appropriate string variable. Follow ALL string variables with the semi-colon (;) delimiter, or the macro won't work properly.

For example, to enter a {TEXT} code into the macro, add the following line in the program:

PRINT #1, text$;

You can enter additional strings for the PRINT #1 statement, up to the 255 character line limit (I like to keep line lengths under 80 characters, for viewing and debugging purposes).

The MAKEMAC.BAS program (and shown in SAMPLE.BAS, above), provides an easy way to enter text strings into macros. You'll use this technique to enter alphanumeric characters into the program, as when entering variable names, prompt messages, and so forth. Follow these steps to include text in the macro:

1. Assign the text to the string prText$, as in

prText$ = "key~Please enter your name  ~"

2. Go to the subroutine doText, as in

GOSUB doText

3. Print the string newString$, as in

PRINT #1, newString$;

Here are some additional tips and techniques you'll want to know about:

 

Using ED

WordPerfect's ED program -- which combines the function of a macro and program editor in one program, can also be used to automatically generate macros. ED comes with the Office/Library package, which is available separately from WordPerfect.

To build a WordPerfect macro, write a generating macro using ED's macro language. Provide the appropriate steps to enter appropriate macro commands, function codes, and so forth. Be sure to specify that you are creating a .WPM file, or ED won't know the proper function keys to use. When the macro file is complete, save it and the customized WordPerfect macro is complete.

 

CREATING DOUBLE-LETTER MACROS

Double-letter macros are activated by pressing a sequence of two keys -- usually an Alt- or Ctrl-letter prefix, and a second key. Double-letter macros expand the number of choices from the 54 available using just the Alt and Ctrl keys.

Double-letter macros consist merely of a {CASE} structure that watches for the second letter. For example, suppose you have written Alt-C as follows:

{CASE}key~~
{CASE}{VARIABLE}key~~
A~doA~    a~doA~
C~doC~    c~doC~ Z~doZ~    z~doZ~
~
{QUIT}

{LABEL}a~
This is the "doA" routine.
{LABEL}c~
This is the "doC" routine.
{LABEL}z~
This is the "doZ" routine.

Start Alt-C and the macro pauses (without displaying a message), waiting for your press the A, C, or Z keys (upper or lower case). Pressing any other key terminates the macro. Pressing one of the keys mapped in the {CASE} structure branches to the appropriate label. What what label routine does is completely up to you, of course.

The message at the {CHAR} is optional. Omitting it simply freezes macro execution until you press a key to go on. If you feel that a message is required, include one.

 

CASE CONVERSION

Expressions used with the {IF} and {WHILE} commands are case-sensitive. Entering a y when the {IF} instruction is looking for Y will yield a result of FALSE. Generally, this isn't what you want, so you enter both y and Y responses into the {IF} construction.

But what if you want to compare an entire string, and don't know how the user will enter the text. For example, if your macro looks for the entry:

I want help

but the user enters

i want help

The result: no match is made.

With a small bit of extra programming, you can readily convert upper-case entries into all lower-case, and vice versa. The following macro segments work with user responses stored in variables. The LCASE.WPM macro converts user entry to lower case; the UCASE.WPM macro converts user entry to upper case. In both macros, only alphabetic characters are converted -- numbers, symbols, and extended characters are left untouched.


LCASE.WPM (provided on the Applications Disk)

{ASSIGN}lcase~~ 
{TEXT}text~Enter the text to convert:  ~ 

{IF EXISTS}text~  {ELSE}{QUIT} 
{END IF} 
 
{ASSIGN}length~{LEN}text~~ 
{FOR}char~0~{VARIABLE}length~~1~ 
{ASSIGN}convert~{MID}text~{VARIABLE}char~~1~~ 
{IF}{KTON}{VARIABLE}convert~~<65|
{KTON}{VARIABLE}convert~~>90~ 
{GO}cont~ 
{ELSE} 
{CALL}casechg~ 
{END IF} 
{LABEL}cont~ 
{ASSIGN}lcase~{VARIABLE}lcase~{VARIABLE}convert~~ 
{END FOR} 

{CHAR}key~{Home} 
Original text:  {VARIABLE}text~{Enter} 
Converted text:  {VARIABLE}lcase~{Enter} 
Press a key to continue~ 
 
{DISPLAY OFF}{DISPLAY ON} 
{ASSIGN}length~~{ASSIGN}char~~{ASSIGN}text~~{ASSIGN}lcase~~ 
{ASSIGN}convert~~ 
{QUIT} 
  {LABEL}casechg~ 
{ASSIGN}convert~{KTON}{VARIABLE}convert~~+32~ 
{ASSIGN}convert~{NTOK}{VARIABLE}convert~~~ 
{RETURN} 

UCASE.WPM (provided on the Applications Disk)
{ASSIGN}ucase~~ 
{TEXT}text~Enter the text to convert:  ~ 
 
{IF EXISTS}text~ 
{ELSE}{QUIT} 
{END IF} 
 
{ASSIGN}length~{LEN}text~~ 
{FOR}char~0~{VARIABLE}length~~1~ 
{ASSIGN}convert~{MID}text~{VARIABLE}char~~1~~ 
{IF}{KTON}{VARIABLE}convert~~<97|
{KTON}{VARIABLE}convert~~>122~ 
{GO}cont~ 
{ELSE} 
{CALL}casechg~ 
{END IF} 
{LABEL}cont~ 
{ASSIGN}ucase~{VARIABLE}ucase~{VARIABLE}convert~~ 
{END FOR} 
  {CHAR}key~{Home} 
Original text:  {VARIABLE}text~{Enter} 
Converted text:  {VARIABLE}ucase~{Enter} 
Press a key to continue~ 
 
{DISPLAY OFF}{DISPLAY ON} 
{ASSIGN}length~~{ASSIGN}char~~{ASSIGN}text~~{ASSIGN}ucase~~ 
{ASSIGN}convert~~ 
{QUIT} 
 
{LABEL}casechg~ 
{ASSIGN}convert~{KTON}{VARIABLE}convert~~-32~ 
{ASSIGN}convert~{NTOK}{VARIABLE}convert~~~ 
{RETURN}

The two macros are essentially the same except for the conversion rules and a few variables. The text to convert is first entered into the text variable. The macro then calculates the length of the string and uses that as the stop value in a {FOR} loop. A {MID} command is used to sample each character in the text string.

An {IF} statement converts the character to its ASCII equivalent (using the {KTON} command). If the characters are within a certain ASCII range (indicating that it is an upper- or lower-case letter), the macro {CALL}s the "casechg" routine. In the UCASE.WPM macro, the "casechg" routine subtracts 32 to arrive at the upper-case character equivalent. In the LCASE.WPM macro, the routine adds 32 to arrive at the lower-case equivalent. Should the value of the character be outside the range indicated in the {IF} structure, the character is left alone (not converted.

At the end of the macro, the original and converted strings are displayed. In addition, the named variables used in the macro are cleared.

You can insert LCASE.WPM and UCASE.WPM as routines in your own macros. Rewrite the macro so that it converts characters in the variable of your choice. Use the converted string as required.

 

PARSING

In the context of computing programming, parsing is the operation of taking a string and dividing it into its constituent parts. Once separated into parts, you can write a macro routine that looks for specific words or other text.

For example, let's suppose you want to know if the user has entered the word "dragon" at a {TEXT} prompt. You're not exactly sure of the context with which the user will enter the word, so instead of writing {IF} structures for every conceivable variation, you write a parser. The parser looks for the word in sentence structure, such as:

The dragon is red The red dragon
Red is the color of the dragon
Not all dragons are red

Most often, you'll want to ignore the case of the text, and convert upper-case to all lower-case, or vice versa. Use the technique outlined earlier in this chapter if you require case conversion of user input.

To parse the user input, follow these steps:

  1. Find the length of the input string, using the {LEN} command.
  2. Build a {FOR} loop with a {MID} command to test for x characters at a time. The number of characters to test is the length of the word you want to locate (for instance, six characters at a time when looking for the word "dragon").
  3. Use an {IF} structure to test each iteration of the {FOR} loop, until the desired word is found. If the {FOR} loop ends without the {IF} instruction ever proving true, then the text string did not include the word you're looking for.

Here's a working example of a parser macro. You can modify this segment and include it in your own macros.

PARSER.WPM (provided on the Applications Disk) {ASSIGN}text~The dragon is red~

{ASSIGN}length~{LEN}text~~ 
{FOR}count~0~{VARIABLE}length~~1~ 
{ASSIGN}parse~{MID}text~{VARIABLE}count~~6~~ 
{IF}"{VARIABLE}parse~"="dragon"~ 
{GO}true~ 
{END IF} 
{END FOR} 
{GO}false~ 
 
{LABEL}true~ 
{CHAR}key~The word "dragon" is part of the text string.  ~ 
{QUIT} 
 
{LABEL}false~ 
{CHAR}key~The word "dragon" is not part of the text string.  ~ 
{QUIT} 

Because of the use of the repeating {FOR} loop and {MID} command, the macro is best used on faster computers (AT-class running at 10 MHz, or faster). In a moderately fast computer, the macro should complete parsing in less than two or three seconds.

If you need to find more than one word in a text string, duplicate the {FOR} loop for each word. For example, you can test if the user entered the words "red" and "dragon."

 

STARTING MACROS FROM DOS

WordPerfect 5.1 lets you initiate a macro upon starting the program the DOS prompt. To execute a macro when you first start WordPerfect, include the /M switch after the WP command line. You should enter the /M switch as the last item if you are using other command-line parameters with WordPerfect.

To indicate the macro to use, enter a dash and the macro name. The macro file should reside either in the default WordPerfect directory or in the macros directory, as defined with the Location of Files option, under the Setup key. For instance, to start a macro called HELLO at the DOS prompt, type

WP /M-hello

and press [Enter].

If you prefer, you can include the /M switch and macro name in a batch file. Run the batch file and the macro is automatically executed when WordPerfect starts.

 

ACTIVATING DOS COMMANDS AND BATCH FILES FROM WITHIN WORDPERFECT

WordPerfect 5.1 lets you momentarily "duck out" to DOS and execute a single DOS command or batch file. You can include the name of the program or batch file in a macro, and use the macro from within WordPerfect to execute the command. Use the following code to execute a DOS program or batch by macro:

{Shell}C
{program/batch name}
{Enter}

The program or batch file you indicated will now run. Press any key to return to WordPerfect.

To display the DIRectory of the current drive, for example, you'd create the following macro:

{Shell}C
dir
{Enter}

 

MISCELLANEOUS TOPICS

Here's a random collection of macro booty you can use to enhance your use of WordPerfect:


Using {GO} to Branch from User Input

WordPerfect does not discern between upper and lower case in label names. You can use this to your advantage to branch to a particular label in a macro from user input. For example, say you want to branch to the "new" routine. Use the following fragment to branch to that command using the entry stored in a variable.

{TEXT}goto~Enter the routine to branch to~
{GO}{VARIABLE}goto~~
...  rest of macro
{LABEL}new~
This is the new label...

The {TEXT} command asks for a routine to branch to; the entry is stored in the goto variable. The next line branches to the label stored in the goto variable -- in this case "new." Note: If you enter a label name that doesn't exist, the macro terminates.


Testing the Version of WordPerfect

Neither WordPerfect 5.0 nor 5.1 incorporate a "version" command so that your macros can tell which program is being used. You may need to restrict your macros to either version. Or you may need to provide two methods of accomplishing the same goals, due to the differences in macro execution between the two versions.

The following snippet of code lets you readily test the version of WordPerfect being used. If the answer is TRUE, then the version used is 5.1 (or later). If the answer is FALSE, the version used if 5.0.

{ASSIGN}1~2*2*2~
{IF}{VAR 1}=8~
    (WordPerfect 5.1)
{ELSE}
    (WordPerfect 5.0)
{END IF}


Forms Fill-In

WordPerfect's tables furnish a convenient method of filling in entry blanks and similar types of data. With the right formatting, you can create forms using one or more tables, and create a macro to automate the fill-in process.

The FILL-IN.WPM macro, shown here, illustrates one technique. The macro is designed to be used with the TESTCELL.TAB file, included on the Applications Disk. This file includes four fill-in entry blanks, for name, age, and so forth. After all entry blanks have been completed, the text is saved and appended to a data file. The form is then cleared, and you can enter new text.


FILL-IN.WPM (provided on the Applications Disk)

{ASSIGN}1~~ 
{ASSIGN}2~~ 
{ASSIGN}3~~  {ASSIGN}4~~ 
 
{FOR}cell~1~4~1~ 
{CALL}wait~ 
{END FOR} 
{GO}capture~ 
 
{LABEL}wait~ 
{ASSIGN}1~~ 
{LABEL}loop~ 
{LOOK}1~ 
 
{CASE}{VAR 1}~ 
{Exit}~exit~ 
{Enter}~enter~ 
{Up}~up~ 
{Down}~down~ 
~ 
 
{IF}"{SYSTEM}cell~"="A{VARIABLE}cell~"~ 
{Right} 
{GO}loop~ 
{ELSE} 
{VAR 1} 
{GO}loop~ 
{END IF}   
{LABEL}exit~ 
{QUIT} 
{LABEL}enter~ 
{Item Down} 
{RETURN} 
{LABEL}up~ 
{Item Up} 
{ASSIGN}cell~{VARIABLE}cell~-2~ 
{ASSIGN}test~{MID}cell~0~1~~ 
{IF}"{VARIABLE}test~"="-"~ 
{ASSIGN}cell~0~ 
{END IF} 
{RETURN} 
{LABEL}down~ 
{Item Down} 
{RETURN} 

{LABEL}capture~ 
{DISPLAY OFF} 
{Item Up}{Item Up}{Item Up} 
{FOR}cell~1~4~1~ 
{Block}{End} 
{Macro Commands}3{VARIABLE}cell~{Enter} 
{Home}{Left} 
{Block}{End}{Delete}y  {Item Down} 
{END FOR} 
 
{Home}{Home}{Up} 
{DISPLAY ON} 
{QUIT}

To use the macro, retrieve the TESTCELL.TAB file and place the cursor in the first blank cell. Start the FILL-IN.WPM macro. Enter the text for the blank, and press [Enter] when you are done. Note that the macro allows you to use the [Up] and [Down] arrow keys to move through the blanks, but won't let you move outside of the entry cells.

Of course, you should modify this macro, as well as the table template document, according to your requirements.

You can force the cursor to go to a particular cell within a table if you need to fill in text there. The Goto key can be used to directly move to a specific cell only when you are editing a table, so the GOTOCELL.WPM macro that prompts you for the cell to go to, turns table editing on, and moves the cursor to the desired cell. If no such cell exists, WordPerfect moves you to the last cell it can.

The EXPENSE.WPM macro, detailed in Chapter 13, shows how this technique can be used for forms fill-in.


GOTOCELL.WPM (provided on the Applications Disk)

{IF}{SYSTEM}document~&512~ 
{TEXT}cell~Enter the cell address you want to go to  ~ 
{DISPLAY OFF} 
{Columns/Tables} 
{Goto}{VARIABLE}cell~{Enter} 
{Exit} 
{DISPLAY ON} 
{END IF}

A practical example of forms fill-in using tables is shown in CHECK.WPM. This macro lets you keep track of your checking account. The check register (which is actually a WordPerfect table) lists transaction type or check number, date, transaction, and amount. WordPerfect keeps track of the running balance, doing the computations for you.

The macro check register system is really composed of four separate files:

To create a new register (which you may want to do on a regular basis, such as once a month): start the MAKEREG macro and enter a beginning balance. The macro automatically formats the new register and attempts to save it as CHECK#.REG. If a CHECK#.REG document already exists, you are given the chance to rename the old document or erase it and replace it with a new one. Once the CHECK#.REG register form is created, you can use the CHECK.WPM macro.

To run CHECK.WPM, start it -- the CHECK#.REG form document is automatically retrieved. Select a function from the menu. You have a choice of enter a check, deposit or other transaction, or editing or saving the register. If you choose to enter a transaction, follow the on-screen prompts and enter the information requested (check number, amount, and so forth).

When you're done with the transaction, answer Yes or No to the prompt that asks if you want to enter another transaction. If you answer No, you are given the chance to:

At any time, you can terminate the macro by pressing Cancel ([F1]). The macro asks if you really want to quit. You can restart the macro or terminate it, accordingly.


CHECK.WPM (provided on the Applications Disk)

{ASSIGN}register~CHECK#.REG~ 
{IF}{SYSTEM}document~!=256~ 
{CHAR}key~{Up}{Up} 
Sorry, the document screen is not empty.  
Save the current document {Enter}(if necessary), and clear the screen
(press Exit n, n).{Enter}Press a key to continue  ~ 
{DISPLAY OFF} 
{DISPLAY ON} 
{QUIT} 
{END IF} 
 
{ON ERROR}{GO}error~~ 
{ON NOT FOUND}{GO}not_found~~ 
{ON CANCEL}{CALL}cancel~~ 
{DISPLAY OFF} 
{Retrieve}{VARIABLE}register~{Enter} 
{DISPLAY ON} 
  {LABEL}trans~ 
{DISPLAY OFF} 
{Home}{Home}{Down} 
{Left Search}*****{Search} 
{DISPLAY ON} 
{CHAR}key~Transaction: 1 C{^\}heck  
{^]}2 D{^\}eposit  {^]}3 O{^\}ther;   
{^]}Register: {^]}4 E{^\}dit  {^]}5 S{^\}ave  
{^]}1{^\}{Left}~ 
{CASE}{VARIABLE}key~~ 
{Enter}~check~ 
1~check~C~check~c~check~ 
2~dep~D~dep~d~dep~ 
3~other~O~other~o~other~ 
4~edit~E~edit~e~edit~ 
5~save~S~save~s~save~ 
~ 
{GO}trans~ 
 
{LABEL}check~ 
{Block Copy} 
{TEXT}key~Enter check number  ~ 
{VARIABLE}key~{Tab} 
{TEXT}key~Enter date of check  ~ 
{VARIABLE}key~{Tab} 
{TEXT}key~Enter description of check  ~  {VARIABLE}key~{Tab} 
{TEXT}key~Enter amount of check  ~ 
{VARIABLE}key~{Tab}{Tab} 
{CALL}calc~ 
{GO}again~ 
 
{LABEL}dep~ 
{Block Copy} 
DEP{Tab} 
{TEXT}key~Enter date of deposit  ~ 
{VARIABLE}key~{Tab} 
{TEXT}key~Enter description of deposit  ~ 
{VARIABLE}key~{Tab}{Tab} 
{TEXT}key~Enter amount of deposit  ~ 
{VARIABLE}key~{Tab} 
{CALL}calc~ 
{GO}again~ 
 
{LABEL}other~ 
{Block Copy} 
{TEXT}key~Enter transaction type  ~ 
{VARIABLE}key~{Tab} 
{TEXT}key~Enter date of transaction  ~ 
{VARIABLE}key~{Tab} 
{TEXT}key~Enter description of transaction  ~ 
{VARIABLE}key~{Tab}   
{LABEL}deb/cred~ 
{CHAR}key~ 
{^]}1 D{^\}ebit Transaction  {^]}2 C{^\}redit Transaction 
{^]}1{^\}{Left}~ 
{CASE}{VARIABLE}key~~ 
1~deb~d~deb~D~deb~ 
2~cred~c~cred~C~cred~ 
{Enter}~deb~ 
~ 
{GO}deb/cred~ 
 
{LABEL}deb~ 
{TEXT}key~Enter amount of transaction  ~ 
{VARIABLE}key~{Tab}{Tab} 
{CALL}calc~ 
{GO}again~ 
 {LABEL}cred~ 
{Tab}{TEXT}key~Enter amount of transaction  ~ 
{VARIABLE}key~{Tab} 
{CALL}calc~ 
{GO}again~ 
 
{LABEL}again~ 
{CHAR}key~{^\}Do another transaction ({^]}Y{^\}es/ {^]}N{^\}o)? 
{^]}Y{^\}{Left}~ 
{CASE}{VARIABLE}key~~ 
{Enter}~trans~ 
y~trans~Y~trans~ 
n~done~N~done~ 
~ 
{GO}again~ 
 
{LABEL}calc~ 
{DISPLAY OFF} 
{Columns/Tables}MC{Exit} 
{DISPLAY ON} 
{RETURN} 
 
{LABEL}done~ 
{CHAR}key~ 
{^]}1 S{^\}ave  {^]}2{^\} Save/{^]}C{^\}lear Screen   
{^]}3 E{^\}dit  {^]}4 R{^\}estart  {^]}5 Q{^\}uit   
{^]}1{^\}{Left}~ 
{CASE}{VARIABLE}key~~ 
{Enter}~save~ 
1~save~S~save~s~save~ 
2~save~C~save~c~save~ 
3~edit~E~edit~e~edit~ 
4~trans~R~trans~r~trans~ 
5~quit~Q~quit~q~quit~  ~ 
{GO}done~ 
 
{LABEL}save~ 
{Save} 
{IF}{SYSTEM}menu~=32809~ 
{VARIABLE}register~{Enter} 
{END IF} 
 
{IF}{SYSTEM}menu~=65027~ 
{Enter}{Enter} 
{VARIABLE}register~{Enter} 
{END IF} 
 
{IF}{SYSTEM}menu~=125~ 
{Enter} 
{VARIABLE}register~{Enter} 
{END IF} 
 
{IF}{STATE}&1024~ 
y 
{END IF} 
 
{IF}{VARIABLE}key~=1|"{VARIABLE}key~"="s"|
"{VARIABLE}key~"="S"~ 
{GO}quit~  {ELSE} 
{Exit}nn 
{GO}quit~ 
{END IF} 
 
{LABEL}edit~ 
{CANCEL OFF} 
{STATUS PROMPT}Edit register; press Exit when done  ~ 
{PAUSE KEY}{Exit}~ 
{STATUS PROMPT}~{DISPLAY OFF} 
{CANCEL ON}{DISPLAY ON} 
{CALL}calc~ 
{GO}trans~ 
 
{LABEL}quit~ 
{ASSIGN}key~~ 
{ASSIGN}register~~ 
{QUIT} 
 
{LABEL}cancel~ 
{CHAR}key~ 
{^]}1 R{^\}eturn  {^]}2 D{^\}elete Transaction  
{^]}3 Q{^\}uit  {^]}1{^\}{Left}~ 
{CASE}{VARIABLE}key~~ 
{Enter}~return~ 
1~return~R~return~r~return~  2~delete~D~delete~d~delete~ 
3~quit~Q~quit~q~quit~ 
~ 
{GO}cancel~ 
 
{LABEL}return~ 
{ASSIGN}key~~ 
{RETURN} 
 
{LABEL}delete~ 
{CANCEL OFF} 
{STATUS PROMPT}{Up}{Del to EOL} 
Move the cursor to transaction; press Enter when done  ~ 
{PAUSE} 
{CANCEL ON}{STATUS PROMPT}~{Screen}{Screen} 
 
{IF}"{SYSTEM}cell~"="F2"~ 
{CHAR}key~Sorry, can't delete the beginning balance.  Press a key to
continue  ~ 
{RETURN} 
{END IF} 
 
{IF}{SYSTEM}document~&512~ 
{BREAK} 
{ELSE} 
{CHAR}key~Sorry, can't delete outside the  register.  Press a key to
continue  ~ 
{RETURN} 
{END IF} 
 
{WHILE}{SYSTEM}column~!=1~ 
{Item Left} 
{END WHILE} 
 
{IF}"{SYSTEM}right~"="*"|"{SYSTEM}left~"="*"~ 
{CHAR}key~Sorry, can't delete that row. 
 Press a key to continue  ~ 
{RETURN} 
{END IF} 
 
{Block Move}y 
{GO}again~ 
 
{LABEL}error~ 
{DISPLAY ON}{CANCEL OFF}{BELL} 
{CHAR}key~Sorry, the {VARIABLE}register~ file cannot be found.  Press
a key to continue  ~ 
{CANCEL ON}{Cancel} 
{GO}quit~ 
 
{LABEL}not_found~ 
{DISPLAY ON}  {BELL} 
{CHAR}key~Sorry, the {VARIABLE}register~ file has been corrupted. 
Press a key to continue  ~ 
{GO}quit~


Using AND to Enter Number Range

The AND (&) can be used in {IF} statements to allow for entry of ranges of numbers, not just specific numbers, or those number greater than or less than some test value. Enter the starting and ending values in one {IF} statement, and separate them with the & operator, as in:

{IF}{VARIABLE}value~>100&{VARIABLE}value~<200~
...

The {IF} statement is true only if the number in the value variable is greater than 100 AND less than 200 (in other words, between 101 and 199.

The GRADES.WPM macro further illustrates the use of the & operator to test for value ranges:


GRADES.WPM (provided on the Applications Disk)

{TEXT}1~Enter grade  ~ 
{IF}{VAR 1}<101&{VAR 1}>89~ 
Grade A  {QUIT} 
{ELSE} 
{IF}{VAR 1}<90&{VAR 1}>79~ 
Grade B 
{QUIT} 
{ELSE} 
{IF}{VAR 1}<80&{VAR 1}>69~ 
Grade C 
{QUIT} 
{ELSE} 
{IF}{VAR 1}<70&{VAR 1}>59~ 
Grade D 
{QUIT} 
{ELSE} 
{IF}{VAR 1}<60~ 
Grade F 
{QUIT} 
{END IF}{END IF}{END IF}{END IF}{END IF}

At the prompt, enter the number grade, such as 86. The macro then compares the numbers to each of five different {IF} statements. The statement is true when the grade falls between the high and low values provided. In the case of a number grade of 86, the macro will respond with "Grade B," because that number falls between 90 and 79.


Macro File Lister

Any collection of more than a few dozen macros becomes hard to catalog and remember. The macro file lister system described here itemizes all of the macro files in a given directory or disk. Once itemized, you can select the macro you want to run by using a point-and-shoot menu macro. If you'd like, you can describe the function of each of your macros so that you know what they do.

The macro file lister system is composed of two parts:

. MAKELIST.WPM -- This macro formats the macro directory document using a "snapshot" you generate at the DOS prompt (more about this in a bit).

. MACLIST.WPM -- This macro retrieves the formatted macro directory document and lets you select a macro to use by pressing the cursor keys. Highlight the one you want and press the [Enter] key.

Follow these steps to generate the macro directory document:

  1. Exit WordPerfect and move to the directory that contains the macro files you want to list (such as CD \WP51\MACROS).
  2. Type: DIR *.WPM > macro.dir and press the [Enter] key. This produces a copy of just the macro files in a file named "macro.dir."
  3. Move back to the WordPerfect 5.1 directory and start WordPerfect.
  4. Run the MAKELIST macro. Indicate the full path of the directory or disk that contains the "macro.dir" document. The MAKELIST.WPM macro will now format the document. The formatted document remains on the screen.
  5. Enter descriptions after the macro names, if desired. Do do that, place the cursor on the line with the macro name you want, then press the [End] key. Press [Tab] two or three times, then enter the description. Don't press the [Enter] key at the end.
  6. Select your regular printer using the Print key.
  7. Save the document and clear the screen.
  8. Edit the MACLIST.WPM macro so that it knows where to find the "macro.dir" document. Provide a path and/or drive, as necessary. Alternatively, you can place the "macro.dir" file in the default WordPerfect directory, or in the directory that contains your document files (as indicated with the Location of Files option under the Setup key).

Note: Be absolutely sure that the formatted "macro.dir" file does not have an extra hard return at

the very end. In addition, the "macro.dir" document uses soft hyphens to delimit the names of macro files from its optional description. Be sure this soft hyphen (which you can view in Reveal Codes) immediately follows the macro name.

To use MACLIST, start it, then press the [Up] and [Down] cursor keys to select the macro you want to use. You can also press the [Home], [End], [Page Up], [Page Down], [Right], and [Left] keys to quickly move through the macro list.


Universal Exit

You may not always be able to predict where your macros will be at any given moment. There may be times when you want to return to the main document screen, but not know how the depth of current menu level. Do you issue one {Exit} or two in your macro?

The short macro fragment that follows can be used as a sort of universal exit. It will return you to the main document screen in almost all instances.

{WHILE} 
{SYSTEM}menu~!=65535~ 
{DISPLAY OFF} 
{Exit} 
{END WHILE} 
{DISPLAY ON}

The macro continually {Exit}s from the current menu level until the {SYSTEM} menu equals 65535. This denotes a WordPerfect editing screen, such as Doc 1, Doc 2, footnote, and so forth.


Special Access Codes

Certain WordPerfect function codes are not directly accessible from the keyboard. You may need to access these codes if you want to use them in for {^P} cursor position coordinates, or otherwise include them in your macro. The following function codes are not accessible directly from the keyboard:

Key 	Value Code
1    	{Compose} 
30   	{Keyboard}
31   	{^_}
86   	{Home-Home-Left}
87   	{Invalid}
106  	{Del Word (Row)}

You can insert these codes using the on-the-fly {NTOK} converter, detailed earlier in this chapter in the "Macro Tools" section. To enter one of these codes in a macro, initiate the on-the-fly {NTOK} converter macro. Then,

For code  	Enter
{Compose} 	0 or 32768
{Keyboard}	30 or 32798
{^_} 		31 or 32799
{Invalid} 	32855 
{Del Word(Row)}	32874

WordPerfect won't let you enter a {Home-Home-Left} code (which is the same as pressing these keys on the keyboard), but you can encode it in a macro by entering:

{NTOK}32854~

The macro will treat this entry as the {Home-Home-Left} code. In fact, you can enter any WordPerfect feature key in this fashion. Appendix E lists all of WordPerfect's feature keys and the associated {NTOK} command value.


Macro Playback Active

Some macros operate in the background, and you'd never know they were active. That can be a problem sometimes. It would be nice if WordPerfect provided a "macro active" prompt that you can turn off an on during macro execution, but such a built-in command does not exist. You can approximate it, however, using the macro fragment shown here.

{STATUS PROMPT}{^P}C 
{^N}{^P}Macro running~ 
{PAUSE} 
{LABEL}off~  
{STATUS PROMPT}~ 
{Screen}{Screen} 
{QUIT}

When the macro is running, a "Macro running" prompt flashes in the upper right corner of the screen. The indicator goes out when the macro terminates. This example temporarily stops the macro with a {PAUSE} command. In your own macro, you'd substitute the {PAUSE} command with your own macro code.

 

IMPORTANT TOPICS

This chapter presented numerous advanced topics for those familiar with WordPerfect's macro programming language.

---

 Top Contents

WordPerfect 5.1 Macros and Templates
Electronic Edition
Copyright 1990, 1997, Gordon McComb.  All Rights Reserved.
First published by Bantam Electronic Publishing, 1990.
http://www.gmccomb.com/