WORDPERFECT MACRO TUTORIAL


9. System Variables

9.1 What are system variables

System variables are special variables that are maintained by the WordPerfect program itself. These variables contain information about current conditions in the program or in the computer system at any given time. System variables contain information about the current cursor position, the particular character or code at the cursor, the states of various settings in the program; in fact, there is a system variable containing information about nearly every aspect of the program. System variables are important because when a macro is played without user intervention (the usual case), the macro must be able to obtain necessary information by itself. The macro does so by accessing the information that WordPerfect maintains in the system variables.

9.2 Names of system variables

System-variable names are self-descriptive, and always begin with a "?" character. Examples: ?LineSpacing, ?BlockActive, ?DocReadOnly. Because these variables are maintained by WordPerfect, you cannot change the names of these variables, or the values they contain. But you can assign the value of a system variable to a variable you created. Example: vOldPage:=?Page assigns the current page number to the variable vOldPage. When the cursor moves to a different page, the value of ?Page changes. But the previous value is still available, since it was stored in vOldPage.

9.3 Documentation on system variables

The on-line help for macros has a comprehensive list of WordPerfect's system variables. To access this documentation, do Help/Help Contents/Macros/Macro Programming/List of Commands/System Variables. You will probably never need to use most of them, but at some point you might need one of the less common system variables. You should look at the list of system variables from time to time to get an idea of what information a macro can obtain from the program.

9.4 System variables to remember

You will probably use the following system variables most often, so you should learn them now:

?LeftChar
Contains the character immediately to the left of the cursor
?LeftCode Contains the numerical equivalent of the code immediately to the left of the cursor
?Line Contains the position of the cursor from the top of the page (in WordPerfect units
?Name Contains the name of the document (if it has been saved)
?Path Contains the path of the document (if it has been saved)
?Page Contains the number of the page where the cursor is located
?Position Contains the position of the cursor from the left edge of the page (in WordPerfect units)
?RevealCodesActive Contains the current setting for reveal codes, on or off ("True" or "False")
?RightChar Contains the character at the cursor
?RightCode Contains the numerical equivalent of the code at the cursor
?SelectedText Contains the contents of the current selection ("block")

9.5 Translating the contents of system variables

The contents of some system variables are readily intelligible and usable. ?RevealCodesActive contains "True" or "False." ?Page contains the number of a page.

But other system variables contain information in a form that is not as easy to understand. For example, ?Line and ?Position contain information expressed in WordPerfect units (there are 1200 WordPerfect units to the inch). You will probably want to have that information expressed in inches (or centimeters). You can do that by performing the appropriate arithmetic operation(s) on the system variable (e.g., dividing the value of the system variable by 1200 to obtain the value in inches). Arithmetic operations are discussed later in the tutorial.

Unfortunately, there is no easy way to translate the contents of ?LeftCode and ?RightCode, which contain the numerical equivalents of codes. These system variables are used mainly to determine if the code being "inspected" is a particular code, so you just need to know if its numerical equivalent matches the numerical equivalent of that code.

The simplest way to find out the numerical equivalent of a code is to position your cursor on that code in a document, and run a macro consisting of the the line Type(?RightCode). This will insert the numerical equivalent of that code into the document.




© 1999 Seth H. Katz
All rights reserved


E-MAIL TO AUTHOR


BACK Table of
Contents NEXT