| October
1997: Using System Variables You can set your own variables in a
WordPerfect macro to keep track of the user's input or progress, or just about any other
thing. There are also variables that you can access from WordPerfect itself. If
WordPerfect keeps track of an item, you can probably use that information in your macros.
What is a system variable?
A system variable is a macro command that can access information that is stored in
memory by WordPerfect. There are literally hundreds of system variables that can be
accessed in a macro. But you'll probably only use a handful on a regular basis. For
example, you may want to find out if a document has been changed since it was last saved;
what the character to the right of the cursor is; if a certain tool bar is currently
displayed on the screen; or if the Select feature is currently active.
How can I reconize a system variable?
System variables are listed in the Command Inserter, and in the online macro help,
although they are usually not referred to as system variables in either of those places.
Most system variable names begin with a question mark, or hook, as the techno-babblers
refer to it.
For example, ?RevealCodes returns a value based on whether
the Reveal Codes feature is active. ?Substructure tells you
whether the cursor is currently in a substructure such as a header or footer. ?BlockActive tells you whether the Select feature is currently turned
on.
The system variable ?Name returns the name of the current
document.
The system variable ?CurrentKeyboard returns the name of the
currently selected keyboard.
If(?BlockActive)
SelectOff()
Endif
Not all system variables have a hook at the beginning of their name. Some system
variables are actually returned when you invoke a command that toggles a feature on or
off. For example, the SpellAsYouGo command returns a
value representing whether that feature is currently active or not, and it can also be
used to turn the feature on and off.
vSAYG:=SpellAsYouGo(Off!)
// do some stuff here
If(vSAYG = True)
SpellAsYouGo(On!) // turn it back on
Endif
Why would I want to use a system variable?
There are all sorts of occasions when you need to adjust what the macro does depending
on a current setting or state in WordPerfect. For example, if the document the macro is
working on needs to be generated, you may want to macro to perform that step. If Select is
on, you may need to turn it off before the macro can perform the next step. You should
always take into account the worst case scenario when writing macros, accommodating for
user error, system settings, or the user's selected preferences. The system variables let
your macro determine what the curent settings are, then adjust as needed.
What information does a system variable return?
The type of information that a system variable returns can be True or False, a numeric
value, or a string of text, depending on what information is being queried. For example,
the system variable ?BlockActive returns a 0 if Select is not
on, and another numeric value if Select is on. The value returned is based on the Select
mode.
When can I use a system variable?
You can use a system variable any time you need to get information about the state of
the document, a certain feature, or the WordPerfect system. Some system variables, such as
those that get information about a table cell, can only be accessed after inserting the
cursor in the table, some care needs to be taken as to when you use a system variable
command in your macro.

For a complete list of the available system variables and their return values, see my book. You can also consult the WordPerfect
Macros online help.
Copyright Notice: The information included in the PerfectScript Journal is protected
by US Copyright. The author grants you the right to use the routines in your own macros as
needed. You may not sell, distribute, or publish them in any form.
If you choose to use the information here, you do so entirely at your own risk. No
representations are made regarding the fitness of this information for your
particular purpose, or for your ability or inability to use the information. You
are advised to make backups of all relevant files before implementing any suggestion
or technique.
© Copyright 1997 by J. Jeppson.
|