Welcome to the Corel® WordPerfect® Office X6 Macro Guide!
This resource contains the following sections:
• PerfectScript macros
• Quattro Pro macros
•VBA macros
• Glossary
PerfectScript macros
PerfectScript™ is a command-based macro-programming language that you can use to automate tasks in
Corel® WordPerfect®, Corel® Quattro Pro®, and Corel® Presentations™. This resource contains basic
information about creating simple PerfectScript macros, as well as detailed, technical information about creating
more complex PerfectScript macros.
This section contains the following topics:
• “Understanding PerfectScript macros” on page 5 — explains the concepts that are associated with macros,
and shows how these concepts apply to PerfectScript macros.
• “Getting started with PerfectScript macros” on page 65 — introduces you to the PerfectScript utility,
which you can use to create macros quickly and easily.
• “Creating PerfectScript macros” on page 69 — examines how to create macros, either by migrating ones
that already exist or by recording or writing new ones.
• “Creating UI for PerfectScript macros” on page 79 — describes how to use a dialog box to create an
interface between the application and the user.
• “Debugging PerfectScript macros” on page 105 — demonstrates how to find and correct any errors in your
macros.
Quattro Pro macros
Quattro Pro macros are stored in notebook cells. Use this type of macro when a task is performed within
Quattro Pro.
This section contains the following topics:
• “Understanding Quattro Pro macros” on page 129 — provides a brief introduction to Quattro Pro macros.
• “Working with Quattro Pro macros” on page 131 — helps you create and edit, play and debug, and
convert Quattro Pro macros.
VBA macros
Microsoft® Visual Basic® for Applications (more commonly known as VBA) is a built-in programming
language that can automate repetitive functions and create intelligent solutions in WordPerfect Office X6. If
VBA 6.3 is installed on your computer, you can access the VBA Editor from within WordPerfect, Quattro Pro,
and Presentations.
VBA 6.3 is not included with WordPerfect Office X6. To use VBA macros, you must separately install
VBA 6.3.
Introduction1
This section contains the following topics:
• “Understanding VBA macros” on page 135 — provides a brief introduction to VBA.
• “Getting started with VBA macros” on page 147 — lets you explore the VBA workspace in WordPerfect,
Quattro Pro, and Presentations.
• “Working with VBA macros” on page 157 — shows you how to create, run, and debug macros.
• “Creating UI for VBA macros” on page 163 — demonstrates how to provide dialog boxes, toolbars and
buttons, user interaction, and help for your macros.
• “Organizing and deploying VBA macros” on page 171 — helps you organize and deploy the macros you
create.
Glossary
This resource also contains a glossary (see page 173).
Please see the Macro Help (psh.chm) for detailed documentation on the available macro commands,
as well as a gallery of sample macros.
When performing repetitive or complex tasks in WordPerfect Office, you can save time by using PerfectScript
macros. In this section, you’ll learn the concepts that are associated with macros, and you’ll learn how these
concepts apply to PerfectScript macros.
This section contains the following topics:
• “Understanding PerfectScript macro concepts” on page 5
• “Using expressions in PerfectScript macro statements” on page 9
• “Using command statements in PerfectScript macros” on page 37
• “Using assignment statements in PerfectScript macros” on page 42
• “Using conditional statements in PerfectScript macros” on page 42
• “Using loop statements in PerfectScript macros” on page 45
• “Using calling statements in PerfectScript macros” on page 46
• “Using comment statements in PerfectScript macros” on page 60
• “Accessing external applications in PerfectScript macros” on page 60
• “Learning more about PerfectScript macros” on page 63
Understanding PerfectScript macro concepts
A macro specifies a sequence of actions that you can quickly repeat later. For example, a macro can automate a
WordPerfect task such as setting the margins, selecting a font, or creating a merge file.
To create macros for WordPerfect Office, you can use the PerfectScript macro-programming language.
PerfectScript is called a “command-based language” because it uses macro commands to store the results of an
action rather than storing the individual steps that are used to carry out that action.
You can also create macros for Quattro Pro by using the native macro-programming language for the
application. For information, see “Quattro Pro macros” on page 127.
You can also use Microsoft Visual Basic for Applications (VBA) to create macros for WordPerfect
Office. For information, see “VBA macros” on page 133.
A macro consists of a set of instructions or statements. By using the various types of macro statements, you can
create PerfectScript macros that automate anything from a basic task to a complex procedure. For more
information about macro statements, see “Understanding PerfectScript macro statements” on page 6.
Through the use of macro statements, PerfectScript lets you create macros that access applications
outside of WordPerfect Office. For more information, see “Accessing external applications in
PerfectScript macros” on page 60.
For even more information about macros, you can consult additional resources for WordPerfect Office.
For information, see “Learning more about PerfectScript macros” on page 63.
The proper form of macro c ompon ents is gov erned by a set o f rule s, or syntax. For more information about macro
syntax, see “Understanding PerfectScript macro syntax” on page 6.
If you structure your macros well, they will function well — and be much easier to edit. For more information
about macro structure, see “Understanding PerfectScript macro structure” on page 6.
Understanding PerfectScript macros5
Understanding PerfectScript macro statements
If a macro represents a set of instructions, then a macro statement represents a single step in those instructions.
The simplest macro consists of only one statement, while the most complex macro consists of multiple
statements that are performed in sequence.
A group of related statements is called a “statement block.”
Some statements require an expression, which is a formula that represents a value. For more information about
expressions, see “Using expressions in PerfectScript macro statements” on page 9.
By combining expressions with other macro components, you can create any of the following types of
statements:
• command statements — consist of a macro command, which represents a single instruction (typically, an
action). For more information, see “Using command statements in PerfectScript macros” on page 37.
• assignment statements — assign a value to an expression. For more information, see “Using assignment
statements in PerfectScript macros” on page 42.
• conditional statements — execute a statement (or a group of statements) when a specified condition is met.
For more information, see “Using conditional statements in PerfectScript macros” on page 42.
• loop statements — execute a statement (or a group of statements) a specified number of times until (or while)
an expression is true. For more information, see “Using loop statements in PerfectScript macros” on
page 45.
• calling statements — call a statement (or a group of statements). For more information, see “Using calling
statements in PerfectScript macros” on page 46.
• comment statements — contain notes that explain the purpose of a macro without affecting its play. For more
information, see “Using comment statements in PerfectScript macros” on page 60.
Understanding PerfectScript macro syntax
The proper form of macro components is governed by a set of rules, or syntax. For a macro to work properly,
its code must use the correct syntax — that is, the code must be “syntactically correct.”
For each macro component that is described in this documentation, details on proper macro syntax are included.
Some macro statements are too lengthy to fit into a single line of macro code. If your macro editor
automatically inserts a hard return at the end of every line, you must insert an underscore character
(
_ ) at the end of each line that wraps. For information on specifying a macro editor, see “To specify
settings for editing macros” on page 67.
Understanding PerfectScript macro structure
If you structure your macros well, they will function well — and be much easier to edit.
You can structure a macro in several ways. The basic function of a macro is to accomplish a task by following a
series of steps, so the ideal structure for a macro depends on the task involved — and on the amount of code
that is required to carry out that task. For example, if a macro involves multiple tasks that require large amounts
of code, you can make the macro more manageable by breaking it into smaller pieces (called subroutines — see
“Understanding subroutines” on page 46).
From a structural standpoint, the two main types of macros are as follows:
6Understanding PerfectScript macro concepts
• sequential macros — progress in steps from start to finish. For more information, see “Understanding
sequential macros” on page 7.
• procedural macros — progress in steps based on user intervention. For more information, see “Understanding
procedural macros” on page 7.
Understanding sequential macros
A sequential macro progresses in steps from start to finish. All steps are taken in the required order, and the
code is written to suit that purpose.
A procedural macro progresses in steps based on user intervention, through the use of functions and procedures
(see “Understanding PerfectScript functions and procedures” on page 48). Using functions and procedures in a
macro lets the programmer compartmentalize code so it can be called from anywhere in the macro.
Compartmentalization breaks logical pieces of code into smaller segments, and these segments can be separated
Understanding PerfectScript macros7
by use of the Label, Function, and Procedure commands (see “Understanding subroutines” on page 46).
Smaller pieces of code are easier to work with, and they are also easier to debug.
An example of a procedural macro follows:
HardReturn ()
HardReturn ()
//Call the function to get the name
sName = GetName()
Type (Text: sName)
HardReturn ()
//Call the function to get the address
sAddress = GetAddress()
Type (sAddress )
HardReturn ()
HardReturn ()
Type (Text: "Dear " + sName + ":")
HardReturn ()
HardReturn ()
Type (Text: "Yaddah Yaddah Yaddah")
HardReturn ()
HardReturn ()
HardReturn ()
Type (Text: "Sincerely,")
HardReturn ()
HardReturn ()
HardReturn ()
HardReturn ()
Type (Text: "Paul Russell")
HardReturn ()
Type (Text: "Manager, Eat-a-Burger, Anywhere, USA")
Function GetName()
GetString( sName; "Type in the name of the addressee"; _
"Enter Name"; 100 )
RETURN( sName )
EndFunction
Function GetAddress()
GetString( sAddress; "Type in the address of the addressee"; _
"Enter Address"; 100 )
8Understanding PerfectScript macro concepts
RETURN( sAddress )
EndFunction
Using expressions in PerfectScript macro statements
Macros consist of statements. Some macro statements involve an action that must be captured as an
expression. An expression is a formula that represents a value.
To create expressions, you use the following macro components:
• variables — store a single value at a time, but this value can change during macro play. For more
information, see “Understanding PerfectScript variables” on page 10.
• constants — store a single value at a time, and this value cannot change during macro play. For more
information, see “Understanding PerfectScript constants” on page 21.
• operators — are symbols (such as
For more information, see “Understanding PerfectScript operators” on page 21.
Understanding expressions
Expressions are created by combining variables or constants (or both) with operators — or by combining other
expressions with operators.
The following examples contain expressions that involve variables and operators.
+, -, *, and %) that combine variables and constants to determine a value.
ExampleResult
x := "John Doe"
vLeftMargin := 5i
ResultOfOperation := 3 + 4
z := z + 1
The variable x equals the character string John Doe.
The variable vLeftMargin equals the measurement 5i.
The variable ResultOfOperation equals 7 (that is, the result of
the numeric expression
3 + 4).
The variable z equals the value of z + 1. However, a variable can
contain only one value at a time, so the original value of
z is lost
unless previously assigned to another variable.
x := y > 1
If (y>1)
Beep
EndIf
The variable x equals the result of the relational expression y > 1
(that is,
equals
x equals True if y contains a value greater than 1, or it
False if y contains a value less than or equal to 1).
The result of y>1 is evaluated without assigning the result to a
variable. The computer beeps if the value of
is, if the result of the expression
skipped if the value of
of the expression equals
y is less than or equal to 1 (that is, if the result
False).
y>1 equals True). The beep is
y is greater than 1 (that
The following example contains expressions that involve variables, constants, and operators. The value
is used as a variable, while the values
expressions from these values:
0, 4, and -1 are used as constants. The operators - and = are used to create
For more information about the types of expressions that you can create, see “Understanding PerfectScript
expression types” on page 32.
Understanding PerfectScript variables
A variable stores a single value at a time, but this value can change during macro play.
Variables must be “declared” before they can be used. Declaring a variable instructs PerfectScript to set aside
memory for the variable.
Assigning a value to — or “initializing” — a variable involves pointing that variable to the memory cell where
its desired value is stored. If desired, variables can be initialized with a value at the time of declaration. Although
the value of a variable can belong to any data type, the most common data types for variables are numbers and
character strings.
For more information about declaring and initializing variables, see “Declaring and initializing variables” on
page 11.
Unlike other programming languages, PerfectScript does not force the programmer to specify the type
of data to be stored in a variable.
When a variable is declared, it is assigned to one of four types:
• local variables — pertain only to the current macro. By default, variables are automatically declared local if
no variable type is specified. For more information, see “Working with local variables” on page 12.
• global variables — pertain to the current macro and to macros that are called by the
commands. For more information, see “Working with global variables” on page 14.
• persistent variables — pertain to any PerfectScript macro, for as long as PerfectScript is running. For more
information, see “Working with persistent variables” on page 15.
Run and Chain
10Using expressions in PerfectScript macro statements
• constant variables — represent a value that cannot change during macro play. For more information, see
“Working with constant variables” on page 16.
Two additional kinds of variables require special attention:
•A system variable is a type of macro command that contains current system information such as
the current chart type or the default directory. For example, the PerfectScript system variable
ErrorNumber contains the error value of a Cancel, Error, or Not Found condition (as
illustrated in line 44 of the annotated macro sample ASSERT.WCM in the Macro Help
[psh.chm]). Similarly, the WordPerfect system variable
name of the default folder for WordPerfect macros to a variable named
?PathMacros assigns the path and
vMacroPath, which is
updated to reflect any changes to the directory. For more information about system variables,
see “Understanding macro commands” on page 37.
•An implicit variable is a variable that is defined by PerfectScript. For example the
MacroDialogResult variable contains the control value of the button that releases a dialog
box (see “Releasing dialog boxes by using PerfectScript code” on page 102).
The type of a variable determines its visibility (or scope) and its duration in memory, so it’s important to
understand when to use each variable type. If you try to access a variable from a line of code in which that
variable is not visible, an “out-of-scope” error is generated.
In addition to variable type, the following factors determine the scope of a variable:
• where the variable is declared — for example, in the main body, in a function, in a procedure, in
another macro, or in a separate program altogether
• which line of code is currently executing
You can check whether a variable exists. For more information, see “Determining whether variables exist” on
page 16.
When a variable is no longer required, you can discard it. For more information, see “Discarding variables” on
page 17.
If you want to assign a collection of data to a single variable name, you can use an array. The rules for using
arrays are the same as for using variables. For more information, see “Working with arrays” on page 18.
Declaring and initializing variables
When you declare a macro, you specify a name for it.
For best results, it is highly recommended that you give your variables a descriptive name. Variable names have
the following standards:
• They must begin with a letter.
• They can include any other combination of letters or numbers.
• They must be 50 characters or fewer in length.
• They are not case-sensitive.
Optionally, you can initialize a variable at its time of declaration by using an assignment operator (
:= or =) to
specify a value.
By following a few simple conventions for naming variables, you can make your macro code easier to
understand. For instance, variables that have a string value should have a name that begins with a lowercase
s,
as in the following examples:
sFirstName := "Dave"
Understanding PerfectScript macros11
sAddress := "1625 East Nowhere St."
sBirthday := "6/12/69"
Similarly, variables that have a numeric value should have a name that begins with a lowercase n, as in the
following examples:
nAge := 25
nTotal := 145.97
In the preceding examples, all declared variables are local, by default, because no variable type is
specified.
Working with local variables
Local variables pertain only to the current macro. Local variables are the default variable type and, as such,
should be used in most situations. You can use the PerfectScript programming commands
Declare or Local
to create local variables.
Variables that are declared in user-defined functions and user-defined procedures are local to those
subroutines. For more information about subroutines, functions, and procedures, see “Understanding
subroutines” on page 46.
Local variables can be declared in the following way:
Declare ( sQReport )
or
Local ( sQReport )
Local variables can be declared and intitialized in the following way:
sQReport := "Q4"
Declare ( sQReport := "Q4" )
or
sQReport := "Q4"
Local ( sQReport := "Q4" )
If you want, you can use the Declare command or the Local command to declare and initialize more than one
local variable at a time. Variables are separated by a semicolon (
When a local variable is declared, it is assigned to the local-variable table. Variables in the local-variable table
are visible only until the end of the level of code in which they are declared. The level of code usually refers to
the main body or a subroutine (that is, a function or procedure). Consider the following sample code:
FileNew
/* Declare sName as a local variable and initialize to the string value "Dave" */
vName := "Dave"
/* Call the procedure */
TypeName ( )
Quit
12Using expressions in PerfectScript macro statements
Procedure TypeName ( )
/* This variable is out of scope. It has not been declared in the procedure TypeName
*/
Type ( vName )
HardReturn
EndProcedure
The preceding code assigns the string "Dave" to the variable. It then calls the procedure which tries to type
the contents of the variable. Because the variable is out of scope within this procedure, the following error occurs
when playing the macro:
Undefined variable ‘VNAME’ has been referenced. Check line 9 of macro file
‘test.wcm.’
Consider the following sample code:
...
/* Variables declared in the main body are visible in the main body */
vNameMain := "Dave"
NewScope ( )
/* When processing this Procedure vNameMain is not visible */
NewScope2 ( )
/* When processing this Function vNameMain is not visible */
...
Quit
// Subroutines . . .
Procedure NewScope ( )
/* Local variables declared in a procedure are visible only in that procedure */
NameNewScope := "Fred"
...
EndProcedure
Function NewScope2 ( )
/* Local variables declared in a function are visible only in that function */
vNameNewScope2 := "John"
...
EndFunction
In the preceding code, all three variables (VNameMain, NameNewScope, and VNameNewScope2) are named
differently. However, these variables could have been named the same and still have been completely unique
variables — each one holding different data — because they are each declared at a different level of the macro
and therefore each have their own scope.
Understanding PerfectScript macros13
Working with global variables
Global variables pertain to the current macro and to macros that are called by the Run and Chain commands.
Although a necessity in some cases, global variables should be used with care. You can use the PerfectScript
programming command
Global to create global variables.
Global variables can be declared in the following way:
Global ( nCount )
Global variables can be declared and initialized in the following way:
Global ( sFilename := "c:\Expense.wpd" )
If you create two variables with the same name (for example, Declare x and Global x), the following
statement specifies that the global variable
Global x:=5
x is assigned the value 5:
If you want, you can use the Global command to declare and initialize more than global variable at a
time by separating variables with a semicolon (
;).
When a variable is declared global, it is assigned to the global-variable table. Variables assigned to the globalvariable table are in scope anytime after they are declared, and they exist until the end of the macro in which
they are declared. If a global variable is declared on the very first line of a macro, it is accessible in the main
body, in subroutines, and in other macros that are started with the commands
Run or Chain. The following is
an example of a global variable in use:
...
/* The global variable is not yet declared and not yet accessible */
Global ( sGlobalName := "Fred" )
/* Any reference after this to the variable sGlobalName accesses the global variable
*/
...
/* Call the function */
DoSomething ( )
Type ( sGlobalName )
...
/* sGlobalName ceases to exist when the macro ends */
Quit
Procedure DoSomething ( )
/* Change the value of the global variable to "Dave" */
sGlobalName := "Dave"
...
EndProcedure
In the preceding example, the procedure is called after the global variable sGlobalName is declared and
initialized. Inside this procedure, the contents of the variable are changed from
commands
DoSomething and Procedure DoSomething allow you to start another macro from within the
"Fred" to "Dave". The
current macro and, therefore, to access and change any variables that are declared global in the current macro.
14Using expressions in PerfectScript macro statements
Working with persistent variables
Persistent variables pertain to any PerfectScript macro, for as long as PerfectScript is running. Although a
necessity in some cases, persistent variables should be used with care. You can use the PerfectScript
programming command
Global command to create global variables.
Persist to create persistent variables — in much the same way as you can use the
Persistent variables can be declared in the following way:
Persist ( VariableName )
Persistent variables can be declared and initialized in the following way:
Persist ( VariableName := Value )
PersistAll ( On! )
...
/* All variables declared in the default manner are now persiste nt instead of local*/
VariableName := Value
...
PersistAll ( Off! )
The preceding example uses the PersistAll command to change the default variable-declaration method from
local to persistent and back again. All variables between
are declared as
Persistent variables. This technique is useful when you want an entire block of variables to be
PersistAll ( On! ) and PersistAll ( Off! )
persistent.
If you want, you can use the
at a time by separating variables with a semicolon (
Persist command to declare and initialize more than persistent variable
;).
When a variable is declared persistent, it is assigned to the persistent-variable table. Variables in the persistent
table remain in scope and exist until PerfectScript shuts down.
PerfectScript does not shut down until all the applications that use PerfectScript (WordPerfect,
Quattro Pro, and Presentations) have shut down.
Persistent variables are visible during merges and, as such, provide an effective method for passing values
between macros and merges. If you need to use data during a merge, use persistent variables. For best results,
give persistent variables a descriptive name, and denote their data type.
The following example of a persistent variable requires the use of two macros and includes a test that determines
whether the variable has been initialized.
The following example illustrates scope by using local and persistent variables:
Persist ( x := "This is persistent variable x" )
Understanding PerfectScript macros15
CreateOutline()
// Original variable value remains unchanged.
MessageBox ( retVal ; "Information"; "The variable x = " + x )
Quit
Procedure CreateOutline ( )
/* PerfectScript will look first at the local variable table. If a variable exists
in that table, that variable will be used before the persistent variable. By
creating a local variable inside the function, we will force PerfectScript to find
the local variable. This local variable x will be destroyed when execution returns
from this subroutine. */
Local ( x := 0 )
ForNext ( x; 1; 10 )
// for loop creates a basic outline
vCharacter := NTOC(96) + x
Tab()
Type ( "(" + vCharacter + ")" )
Indent()
HardReturn()
EndFor
EndProcedure
Working with constant variables
Constant variables — also called “constants” — represent a value that cannot change during macro play. As
such, constants must be initialized upon declaration, and their assigned value cannot change. Constants should
be used sparingly, if at all.
Expressions are formed by using operators (see “Understanding PerfectScript operators” on page 21) to combine
constants with other types of variables. For more information about constants, see “Understanding PerfectScript
constants” on page 21.
Determining whether variables exist
You can use the Exists command to determine whether a variable exists — that is, whether it has been declared
and initialized. The following sample code shows how to use the
// Declare and initialize a variable’s Name := "Fred"
// Use Exists to see if the variable still exists as a local variable
If ( Exists ( sName; Local! ) )
...
EndIf
...
Quit
Exists command:
The Exists command returns a value after checking the specified variable against the variable tables. The
variable tables are checked in the following order: local, then global, then persistent.
16Using expressions in PerfectScript macro statements
If you specify a variable-table parameter for the Exists command, a value of True is returned if that variable
is found in the specified variable table. If the variable is not found in the specified variable table, a value of
False
is returned. The following example illustrates this scenario:
If( Exists ( x ; Global!) = TRUE )
x := 147
Else
Global ( x := 147 )
EndIf
If you do not specify a variable-table parameter for the Exists command, one of the following values is
returned:
•
NotFound! or 0 — indicates that the variable does not exist in any variable table
•
Local! or 1 — indicates that the variable exists in the local-variable table
•
Global! or 2 — indicates that the variable exists in the global-variable table
•
Persistent! or 3 — indicates that the variable exists in the persistent-variable table
The following example illustrates this scenario:
Persist( x := 3 )
If ( Exists( x ) = Exists.Persistent!)
MessageBox ( retVar; "Variable"; "This variable Exists in the _
Persist variable pool (" + Exists ( x ) + ")" )
EndIf
Discarding variables
You can use the Discard command to remove a variable from memory by deleting it from its associated variable
table. The following sample code shows how to use the
// Declare and initialize a variable
sName := "Fred"
...
// Free the memory used by vName
Discard ( sName )
// sName no longer exists and cannot be accessed
...
Quit
Discard command:
The Discard command searches the variable tables in the following order: local, then global, then persistent.
If variables with the same name exist in different variable tables, you may need to use the
If you want, you can assign a collection of data to a single variable name by creating an “array.” The elements in
a PerfectScript array can be declared and initialized in the same ways as variables. Unlike other programming
languages, however, PerfectScript lets you assign the elements in an array to different data types. PerfectScript
arrays therefore provide a powerful way to control large amounts of data on one or more dimensions.
To use an array, you must first declare it and initialize its elements. When a macro is played, a run-time error is
incurred for each array element that is not both declared and initialized.
The commands for declaring arrays are the same as for declaring variables:
Persist. At declaration, an array requires the following items:
Declare, Local, Global and
• an alphanumeric (case-insensitive) name that begins with a letter and is limited to 50 characters
• a subscript, marked in brackets (
[]), that specifies how many array elements to create
The following commands declare a one-dimensional array that contains five elements:
Declare(aMyArray[5]) — declares a one-dimensional, five-element local array
•
•
Local(aMyArray[5]) — declares a one-dimensional, five-element local array
•
Global(aGlobalArray[5]) — declares a one-dimensional, five-element global array
•
Persist(aPersistArray[5]) — declares a one-dimensional, five-element persistent array
Every array contains a hidden element called
0. This element stores the total number of elements in the
array (not including itself), and an attempt to assign any other value to this element generates an error
message. In the previous examples, the declared array actually includes six elements if you include
element
0.
The preceding examples declare an array but do not initialize its elements. Before you can use an array, you must
individually initialize each array element. To initialize an array element, you must specify the array name; the
subscript (or index) number of the array element, enclosed in brackets (
[]); and the desired value for the array
element. The following example illustrates how to initialize each element in an array after declaring the array.
// Declare a 5-element array
Declare ( aMyArray[5] )
// Initialize each of the five elements
aMyArray[1] := "One"
aMyArray[2] := "Two"
aMyArray[3] := "Three"
aMyArray[4] := "Four"
aMyArray[5] := "Five"
You can simplify the process of initializing array elements after declaring an array by using the following syntax:
18Using expressions in PerfectScript macro statements
If you want, you can initialize an array upon its declaration (in which case, the number of elements need not be
specified). The following commands declare and initialize a one-dimensional array that contains five elements:
Declare(aMyArray[]:={"One";"Two";"Three";"Four";"Five"}) — declares and initiatlizes a one-
•
dimensional, five-element local array
•
Local(aMyArray[]:={"One";"Two";"Three";"Four";"Five"}) — declares and initiatlizes a one-
dimensional, five-element local array
aMyArray[]:={"One";"Two";"Three";"Four";"Five"} — declares and initiatlizes a one-
•
dimensional, five-element local array
Global(aGlobalArray[]:={"One";"Two";"Three";"Four";"Five"}) — declares and initiatlizes a
•
one-dimensional, five-element global array
•
Persist(aPersistArray[]:={"One";"Two";"Three";"Four";"Five"}) — declares and initiatlizes
a one-dimensional, five-element persistent array
PerfectScript arrays can have up to ten dimensions. A two-dimensional array is like a table with rows and
columns: Each cell in the table is an individual element.
For declaring a multi-dimensional array, the syntax of the subscript operator (
of dimensions is followed by a semicolon (
;), which is followed by the number elements within each dimension.
[]) is as follows: The number
The following example shows how to declare a three-dimensional array in which each dimension has five
elements:
Declare ( aMyArray[3;5] )
Each dimension can have up to 32,767 elements (depending on available memory), and each element can be
individually accessed and initialized. For accessing and initializing an element in a multi-dimensional array, the
syntax of the subscript operator (
semicolon (
;), which is followed by the subscript (or index) number of the element within that dimension.
[]) is as follows: The dimension number of the element is followed by a
The following syntax specifies the first element in the first dimension:
aMyArray[1;1] := "1-1"
The following syntax specifies the third element in the second dimension:
aMyArray[2;3] := "2-3"
The following stynax specifies the fifth element in the third dimension:
aMyArray[3;5] := "3-5"
Multi-dimensional arrays, like one-dimensional arrays, can be initialized at their time of declaration. In this
scenario, the number of elements in each dimension does not need to be explicitly stated because it is implied
by the actual initialization of those elements. In addition, the dimensions are separated by a semicolon (
;). The
following example illustrates this syntax:
aMyArray[] :=
{{"1-1"; "1-2"; "1-3"; "1-4"; "1-5"}; // First row
{"2-1"; "2-2"; "2-3"; "2-4"; "2-5"}; // Second row
{"3-1"; "3-2"; "3-3"; "3-4"; "3-5"} } // Third row
PerfectScript provides a special form of initialization for multi-dimensional arrays. This form, called a slice (...),
lets you initialize the elements on a single dimension by repeating the last-initialized element throughout that
dimension. When initializing with a slice, you must fully initialize at least one row in each dimension to define
the extent of the slice. The following example illustrates the syntax for using a slice:
Understanding PerfectScript macros19
// Declares a three-dimensional array (3x3x6) initializing all elements wit h a slice
aMyArray[] :=
{ { {1;1;1;1;1;1}; // First dimension, first row
{1; ... }; // First dimension, second row, replicated with value 1
{1; ... } }; // First dimension, third row
{{2;2;2;2;2;2}; // Second dimension, first row
{2; ... }; // Second dimension, second row
{2; ... } }; // Second dimension, third row
{{3;3;3;3;3;3}; // Third dimension, first row
{3; 4, ... }; // Third dimension, second row, replicated with value 4
{3; 1; ... } } } // Third dimension, third row, replicated with _ value 1
You can use the Dimensions command to return the following information about an array:
• total number of dimensions in the array
• total number of elements in the array
• number of elements in each dimension
• index range
In some cases, you must declare an array dynamically and therefore cannot be sure how many dimensions are
contained in the array. The
Dimensions command allows a macro to act dynamically by querying the size of
an array:
aFiles[] := GetFileList() // returns an array of random size
ForNext (x; 1; Dimensions( aFiles[]; 0 ) )
// Dimensions queries the array for the size
FileOpen ( aFiles[x] )
FooterA(Create!)
Type ( "McRae's Eat-a-Burger ")
SubStructureExit()
FileSave ( aFiles[x]; WordPerfect_60! )
Close()
EndFor
Function GetFileList()
... // statement block that creates an array (sized) dynamically
Return ( ArrayOfFiles[] )
EndFunction
Please note that MacroArgs[] is a special PerfectScript array that contains values that are passed to the macro
by the commands
// Macro: MAIN.WCM
// Include full path if macro not
// in default macros directory
Chain, Nest, or Run. The following example illustrates the MacroArgs[] array.
20Using expressions in PerfectScript macro statements
Run("TSTMACRO"; {"x"; "y"; "z"})
// Macro: TSTMACRO.WCM
// Compile, then play MAIN.WCM
vElements = Dimensions (MacroArgs[]; 0)
If (vElements != 0)
ForNext (x; 1; vElements; 1)
MessageBox (z; "Element Values"; "MacroArgs[" + x + "] = " + _
MacroArgs[x])
EndFor
Else
Beep
MessageBox (z; "Error"; "No values passed"; IconExclamation!)
EndIf
// Result: x y z
Understanding PerfectScript constants
A constant — also called a constant variable — represents a value that cannot change during macro play.
By contrast, most variables represent a value that can change during macro play. For more information,
see “Understanding PerfectScript variables” on page 10.
Constants must be initialized upon declaration, and their assigned value cannot change. You can declare and
initiatlize a constant in the following way:
Constant ( WPCLASSNAME := "WordPerfect.8.32" )
A compile-time error occurs if a constant is misused in one of the following ways:
• if the constant is not initialized upon declaration — for example, if the declaration statement is missing an
assignment operator (
:=) or an assigned value (or both)
• if an attempt is made to assign a different value to a constant after it has been declared and initialized
You can set constants apart from other variables by giving them a name that appears entirely in capital
letters. This naming convention is the generally accepted practice in C/C++ and other programming
languages.
Understanding PerfectScript operators
Operators are used to combine variables (see “Understanding PerfectScript variables” on page 10) and
constants (see “Understanding PerfectScript constants” on page 21) into expressions — and even to combine
expressions into other expressions. In PerfectScript, operators can be either “unary” or “binary.”
Unary operators are symbols or words that represent an operation on only one operand or expression. The
following table lists the unary operators that are available in PerfectScript.
Understanding PerfectScript macros21
OperatorActionExample and result
+
-
NOT
~
Multiplies an operand by +1
Multiplies an operand by -1
Inverts the result of relational and logical
expressions
To g gle s a bi n ar y v a lu e (that is, converts 1 to
0, and 0 to 1)
+5
Result: +5 (that is, 5 * +1)
-10
Result:-10 (that is, 10 * -1)
See “Understanding logical operators” on page 26.
See “Understanding bitwise operators” on page 28.
Binary operators are symbols or words that represent an operation on two operands or expressions. In the
following example, the binary plus operator (
assigns the result of the arithmetic expression
x := 3 + 4
+) adds the operands 3 and 4, and the assignment operator (:=)
3 + 4 to variable x.
All PerfectScript operators can be classified into the following functional categories:
• assignment operators — symbols that assign the value of a right-operand expression to a left-operand variable.
For more information, see “Understanding assignment operators” on page 22.
• arithmetic operators — symbols or words that represent a mathematical operation on two operands. For more
information, see “Understanding arithmetic operators” on page 23.
• relational operators — symbols that represent a relational operation on two operands, such that the operation
result equals either true or false. For more information, see “Understanding relational operators” on
page 24.
• logical operators — words that represent a logical relationship between conditions, or that invert a condition.
For more information, see “Understanding logical operators” on page 26.
• bitwise operators — symbols that represent a bitwise operation on two integer operands. For more
information, see “Understanding bitwise operators” on page 28.
When used together to form an expression, operators are evaulated by PerfectScript based on precedence level.
For more information about operator precedence, see “Understanding operator precedence” on page 30.
For detailed information on each operator, please see the “Operators” topic in the PerfectScript
Command Reference section of the Macro Help (psh.chm).
Understanding assignment operators
Assignment operators are symbols that assign the value of a right-operand expression to a left-operand variable.
The following table lists the assignment operators that are available in PerfectScript.
OperatorActionExample and result
:= or =Assignment of a value to a variable
22Using expressions in PerfectScript macro statements
x := "John Doe"
Result: The variable x equals the character string
John Doe.
Understanding arithmetic operators
Arithmetic operators are symbols or words that represent a mathematical operation on two operands.
All arithmetic operators are binary operators.
The following table lists the arithmetic operators that are available in PerfectScript.
OperatorActionExample and result
*
/
-
+
%
MOD
Multiplication
Division
Subtraction of numbers and
reduction of strings
Addition of numbers and
concatenation of strings
Floating point modulus division
— returns remainder of floatingpoint division
Integer modulus division —
returns remainder of integer
division
vStr := "abcdefg" - "efg"
Result: vStr equals "abcd" (by reduction of strings)
vStr := "abcd" + "efg"
Result: vStr equals "abcdefg" (by concatenation of strings)
x:=10.1 % 3
Result: x equals 1.1
x := 9 % 3
Result: x equals 0
x := 10 MOD 3
Result: x equals 1
x := 10.1 MOD 3
Result: error (because MOD cannot be used on real numbers)
DIV
Integer division — returns
integer portion of integer division
x := 10 DIV 3
Result: x equals 3
x := 9 DIV 3
Result: x equals 3
x := 9.1 DIV 3.5
Result: error (because DIV cannot be used on real numbers)
**
Exponentiation — raises a
number to a power
vResult = 2**3
Result: vResult = 8 (that is, 2 to the power of 3)
vResult = 4**2
Result: vResult = 16 ( that is, 4 to the power of 2)
Understanding PerfectScript macros23
Understanding relational operators
Relational operators are symbols that represent a relational operation on two operands. The operation result
True or False.
equals
All relational operators are binary operators.
The following table lists the relational operators that are available in PerfectScript.
OperatorActionExample and result
>
>=
<
<=
Greater than
Greater than or equal to
Less than
Less than or equal to
x := 10
z := (x>5)
Result: z equals True (because x is greater than 5)
x := 10
If (x>=10)
Beep
Else
Quit
EndIf
Result: The computer beeps because the result of expression x >=
10
equals True (that is, x equals 10). The Else statement is
skipped, so the
x := 10
z := (x<5)
Quit command does not end the macro.
Result: z equals False (becuase x is not less than 5)
x := 20
If (x<=10)
Beep
Else
Quit
EndIf
Result: The computer does not beep because the result of expression
x <= 10 equals False (that is, x is greater than 10). The Else
statement is played, so the
Quit command ends the macro.
24Using expressions in PerfectScript macro statements
OperatorActionExample and result
=
<>
Equal to
Note: Whereas
True regardless of whether
LIKE is
the compared strings are
identical in case,
= is case-
sensitive.
Not equal to
x := 10
z := (x=5)
Result: z equals False (because x is not equal to 5)
x := 10
z := (x = 10)
Result: z equals True (becuase x is equal to 10)
x := "Abc"
z := (x = "Abc")
Result: z equals True ( because x is equal to "Abc")
x := "Abc"
z := (x = "abc")
Result:z equals False (because x must be the same as "Abc",
including case)
!=
Not equal to
x := 10
z := (x!=5)
Result: z equals True (because x is not equal to 5)
x := 12
z := (x !=12)
Result: z equals False (because x is equal to 12)
Understanding PerfectScript macros25
OperatorActionExample and result
IN
LIKE
Membership
Case-insensitive string
equality
Note: Whereas
= is True
only if the compared strings
are identical in case,
LIKE
disregards case altogether.
z := 3 IN {1; 2; 3}
Result: z equals True
z := 3 IN (1; 2; 4}
Result: z equals False
z := {1; 2; 3} IN {1; 2; 3}
Result: z equals True
z := {1; 2} IN {1; 2; 3}
Result: z equals True
z := {1; 2; 3} IN {1; 2; 4}
Result: z equals False
z := ("abc" LIKE "Abc")
Result: z equals True
Understanding logical operators
Logical operators are words that either invert one condition or represent a logical relationship between
conditions. A condition is the result of a relational expression (see “Understanding relational expressions” on
page 36).
Most logical operators are binary operators. The exception is
NOT.
The following table lists the logical operators that are available in PerfectScript.
OperatorActionExample and result
NOT
26Using expressions in PerfectScript macro statements
Inverts the result of a relational
expression
See also the detailed NOT examples that follow this table.
x := 8
If ((x<10) AND NOT (x=5))
Beep
EndIf
Result: The result of the logical expression equals True
( because
x is not equal to 5).
x is less than 10, AND NOT x is equal to 5, or
OperatorActionExample and result
AND
XOR
Combines two relational expressions.
Each expression must be
logical expression to be
True for the
True.
Combines two relational expressions.
Only one expression can be
the logical expression to be
both are true or both are
logical expression is
True for
True. If
False, the
False. The XOR
function is also called “exclusive OR.”
x := 1
y := 2
z := ((x = 1) AND (y = 2))
Result: z equals True. The logical AND expression is
True because both the relational expressions x = 1
y = 2 are True.
and
See also the detailed XOR example that follows this table.
x := 1
y := 2
z := ((x = 0) XOR (y = 2))
Result:z equals True (because only one relational
expression is
z := ((x = 1) XOR (y = 2))
True)
Result:z equals False (because both relational
expressions are
True)
OR
Combines two relational expressions.
Only one expression needs to be
for the logical expression to be
True
True.
The OR function is also called “inclusive
OR.”
Here are some more detailed examples of NOT.
NOT ExampleResult
x := 5
y := (x<10)
z := NOT(x<10)
If x is less than 10, True is assigned to y and False (that is, the
inverted result of the expression
z := ((x = 0) XOR (y = 1))
Result:z equals False (because both relational
expressions are
x := 1
y := 2
z := ((x = 1) OR (y = 5))
False)
Result: z equals True. The logical OR expression is
True because the relational expression x = 1 is True.
x<10) to z.
Understanding PerfectScript macros27
NOT ExampleResult
x := 5
z := (x<10)
If (NOT(z))
Beep
Else
Quit
EndIf
x := 5
If (NOT(x<10))
Beep
Else
Quit
EndIf
x := 5
If (x>10)
Beep
Else
Quit
The result of the expression x<10 is assigned to variable z. The Beep
command causes the computer to beep if the inverted value of
True. However, the inverted value of z equals False, so there is no
beep; the
Else statement is played, and the Quit command ends the
z equals
macro.
NOTE: For more information about
If conditions, see
“Understanding If conditions” on page 43.
In this shorthand notation, the computer is instructed to beep if the
inverted result of the expression
result of
NOT(x<10) equals False, so there is no beep; the Else
statement is played, and the
x<10 equals True. However, the
Quit command ends the macro.
This example represents an alternative to using the NOT operator. If
the result of the expression
However, the result equals
10), so the Else statement is played and the Quit command ends the
x>10 equals True, the computer beeps.
False (because the value of x is less than
macro.
EndIf
Here is a more detailed example of XOR.
XOR ExampleResult
x := 1
y := 2
If ((x = 0) XOR (y = 2))
Beep
EndIf
In this shorthand notation, the result of the logical XOR expression
True because the relational expression x = 0 is False and the
equals
relational expression
y = 2 is True.
Understanding bitwise operators
Bitwise operators are symbols that represent a bitwise operation on two-integer operands.
Most bitwise operators are binary operators. The exception is bitwise NOT (
~).
The following table lists the bitwise operators that are available in PerfectScript.
28Using expressions in PerfectScript macro statements
OperatorActionExample and result
~
Toggles a binary value (that is, converts 1 to
0, and 0 to 1). Also called “bitwise unary
NOT” — “unary” because it has a single
complement.
&
Results in 1 if both operand bits are 1, 0 if
one of the operand bits is not
operands are
0. Also called “bitwise AND.”
1, or 0 if both
~-15
Note: The binary equivalent of
-15 is 1111111111110001.
Result:
x:=1000&31
14 (binary 0000000000001110)
Note: The binary equivalent of 1000 is
1111101000 and of 31 is 0000011111.
Result:
x:=65535&535
x equals 8 (binary 0000001000)
Note: The binary equivalent of 65535 is
1111111111111111 and of 535 is
0000001000010111.
Result:
0000001000010111)
|
Results in 1 if either operand is 1. Also called
“bitwise inclusive OR.”
x:=1000|27
Note: The binary equivalent of 1000 is
1111101000 and of 27 is 0000011011.
Result:
x equals 535 (binary
x equals 1019 (binary 1111111011)
x:=65535|535
Note: The binary equivalent of 65535 is
1111111111111111 and of 535 is
0000001000010111.
Result:
1111111111111111)
^
Results in 0 if operands match, 1 otherwise.
Also called “bitwise exclusive OR (XOR)”.
x:=1000^40
Note: The binary equivalent of 1000 is
1111101000 and of 40 is 0000101000.
Result:
x:=65535^535
x equals 65535 (binary
x equals 960 (binary 1111000000)
Note: The binary equivalent of 65535 is
1111111111111111 and of 535 is
0000001000010111.
Result:
1111110111101000)
x equals 65000 (binary
Understanding PerfectScript macros29
OperatorActionExample and result
<<
>>
Shifts bits left by the specified number of
places. For example, specifying
1 place shifts
all bits one place to the left (and inserts a
at the right end of the binary number,
effectively multiplying the value by 2.
Shifts bits right by the specified number of
places. For example, specifying
1 place shifts
all bits one place to the right (and inserts a
at the left end of the binary number,
effectively dividing the value by 2.
x:=500<<1
Note: The binary equivalent of 500 is
0
0111110100.
Result:
x:=65535<<1
x equals 1000 (binary 1111101000)
Note: The binary equivalent of 65535 is
1111111111111111.
Result:
1111111111111110)
x:=1000>>1
Note: The binary equivalent of 1000 is
0
1111101000.
Result:
x:=65535>>1
x equals 131070 (binary
x equals 500 (binary 0111110100)
Note: The binary equivalent of 65535 is
111111111111111.
<<<
>>>
Rotates bits left by the specified number of
places. For example, specifying
1 rotates all
bits one place to the left.
Rotates bits right by the specified number of
places. For example, specifying
1 rotates all
bits one place to the right.
Result:
0111111111111111)
x:=-2147450881<<<1
Note: The binary equivalent of
-2147450881 is
10000000000000000111111111111111.
Result:
00000000000000001111111111111111)
x:=65535>>>1
Note: The binary equivalent of 65535 is
00000000000000001111111111111111.
Result:
10000000000000000111111111111111)
x equals 32767 (binary
x equals 65535 (binary
x equals -2147450881 (binary
Understanding operator precedence
The following table explains operator precedence, which is used by PerfectScript to evaluate expressions.
30Using expressions in PerfectScript macro statements
Precedence levelOperators
1• parentheses [
• unary minus (
• unary plus (
•bitwise not (
•logical not (
2• exponentiation (
3• multiplication (
• division (
• modulus division (
• integer division (
4• addition (
• subtraction (
5• left shift (
• right shift (
• left rotation (
• right rotation (
6•equality (
•inequality (
• “less than” state (
• “less than” state or equality (
• “greater than” state (
()]
-)
+)
~)
NOT)
**)
*)
/)
% or MOD)
DIV)
+)
-)
<)
>)
<)
>)
=)
!=)
<)
<=)
>)
• “greater than” state or equality (
•membership (
IN)
• case-insensitive string equality (
>=)
LIKE)
7•bitwise and (
•bitwise or (
•bitwise XOR (
8•logical and (
9•logical or (
•logical xor (
10• assignment (
&)
|)
^)
AND)
OR)
XOR)
:= or =)
The following rules apply to operator precedence:
• Operators with the same precedence are evaluated from left to right.
• Operators inside parentheses are evaluated before operators outside parentheses.
• Operators inside nested parentheses are evaluated from the innermost parentheses out.
Here are some examples that illustrate operator precedence.
Understanding PerfectScript macros31
ExampleResult
x := ((50 * 5 + 50) * 3 + 100)
x := ((50 * (5 + 50)) * 3 + 100)
x := ((50 * 5 + 50) * (3 + 100))
x
equals 1000:
• 50 * 5 = 250
• 250 + 50 = 300
• 300 * 3 = 900
• 900 + 100 = 1000
x
equals 8350:
• 5 + 50 = 55
• 55 * 50 = 2750
• 2750 * 3 = 8250
• 8250 + 100 = 8350
x
equals 30900:
• 50 * 5 = 250
• 250 + 50 = 300
• 3 + 100 = 103
• 300 * 103 = 30900
Understanding PerfectScript expression types
By combining variables (see “Understanding PerfectScript variables” on page 10) and constants (see
“Understanding PerfectScript constants” on page 21) with operators (see “Understanding PerfectScript
operators” on page 21), you can form expressions for use in macro statements.
PerfectScript macros support the following expression types:
• numeric expressions — numeric variables or numeric constants, or a combination of the two as joined by a
numeric operator. For more information, see “Understanding numeric expressions” on page 33.
• measurement expressions — variables or constants that contain a measurement value, or a combination of the
two as joined by a numeric operator. For more information, see “Understanding measurement expressions”
on page 33.
• radix expressions — values that combine a number with a character that identifies the “radix” for that
number (that is, the base of its number system). For more information, see “Understanding radix
expressions” on page 34.
• character expressions — variables or character constants (such as letters, digits, or keyboard symbols), or a
combination of the two as joined by the plus operator (
+), the minus operator (-), or a relational operator.
For more information, see “Understanding character expressions” on page 34.
• arithmetic expressions — statements that represent arithmetic operations, or statements that contain two
operands that are joined by an arithmetic operator. For more information, see “Understanding arithmetic
expressions” on page 35.
• relational expressions — statements that represent a relational operation, or statements that contain two
operands that are joined by a relational operator. For more information, see “Understanding relational
expressions” on page 36.
• logical expressions — statements that represent logical operations, or statements that contain two relational
expressions that are joined by a logical operator. For more information, see “Understanding logical
expressions” on page 36.
32Using expressions in PerfectScript macro statements
• bitwise expressions — statements that represent bitwise operations, or statements that contain two operands
that are joined by a bitwise operator. For more information, see “Understanding bitwise expressions” on
page 37.
Command calls and function calls can be used in an expression if they return a value. For more
information, see “Using calling statements in PerfectScript macros” on page 46.
Understanding numeric expressions
Numeric expressions are numeric variables or numeric constants — or a combination of the two as joined by a
numeric operator.
Given that
ExampleExplanation
x
5
x * 5
+5
-(x + 10)
Understanding measurement expressions
x equals 3, the following examples are valid numeric expressions.
Variable that contains a numeric value
Numeric constant
Expression that multiplies x by 5
Note: This expression is also an arithmetic expression.
Unary plus constant
Unary minus expression, which negates the result of x plus 10
Measurement expressions are variables or constants that contain a measurement value — or a combination of
the two as joined by a numeric operator. A measurement value is created by combining a number (which
represents the desired number of units) with a character (which identifies the desired unit of measurement).
The available units of measurement, and their associated identifiers, are as follows.
Unit of measurementIdentifier
Inches
" or i
Centimeters
Millimeters
Points (72 per inch)
WP units (1200 per inch)
c
m
p
w
You can add and subtract measurement expressions as you do numeric expressions (see “Understanding numeric
expressions” on page 33). When an operation is performed on measurement expressions that have different
units of measure, the right operand is converted to the type of the left-measurement operand.
Combining numeric expressions with measurement expressions can produce unexpected results.
You do not need to specify a unit of measure for command-measurement expressions that follow
DefaultUnits.
Understanding PerfectScript macros33
If you do not specify a unit of measure for a measurement expression, and DefaultUnits has not been
encountered, the default unit of measurement WP units (1200 per inch) is used.
Given that
z equals 4i (that is, 4 inches), the following examples are valid measurement expressions.
ExampleExplanation
5c
z
z * 10i
-z
Constant (5 centimeters)
Variable that contains a measurement value of 4 inches
Expression that multiplies z by 10i (that is, 10 inches)
Unary minus, which yields -4i (that is, negative 4 inches)
Understanding radix expressions
The radix is the base of a number system. Radix expressions contain a radix value, which is created by combining
a number (which represents the number value) with a character (which identifies the radix).
A radix value must begin with a number. For this reason, you must place a zero before any hexadecimal
numbers that begin with the letters
A through F.
The available radix choices, and their associated identifiers, are as follows.
RadixIdentifier
16 (hexadecimal system)
8 (octal system)
x or h
o
2 (binary system)
b
The following examples are valid radix expressions.
ExampleResult
x := 1Ah
x := 0Ah
x := 1111b
x := 44o
x
equals the hexidecimal value of 26
x
equals the hexidecimal value of 10
Note: A numeric value of
must use
x
equals the binary value of 15
x
equals the octal value of 36
0Ah.
Ah is not valid because it does not begin with a number. Instead, you
Understanding character expressions
Character expressions are character variables or character constants (such as letters, digits, or keyboard symbols)
— or a combination of the two as concatenated by the plus operator (
or compared by a relational operator (such as
>).
+), separated by the minus operator (-),
A character constant that is enclosed in single quotation marks specifies an ASCII numeric value, as in the
following examples.
34Using expressions in PerfectScript macro statements
ExampleResult
x := ‘A’
x := ‘A’ + ‘B’
x
equals 65
equals 131 (that is, 65 + 66)
x
A character string must be enclosed in double quotation marks. If the string already contains double quotation
marks, it must use a second set of double quotation marks, as in the following examples.
ExampleResult
x := "His name is "John"" Doe"
x := """John Doe"""
x
equals His name is "John" Doe
x equals "John Doe"
The following examples are valid character expressions.
ExampleExplanation
"John Doe"
z := "Joe " + "Doe"
x := z + ", Jr."
Character string
Expression that is assigned to variable z (such that z equals Joe Doe)
Expression that is assigned to variable x (such that x equals Joe Doe, Jr.)
If you concatenate a character string and a number, the number is converted to a character string. If you
concatenate a numeric character and a number, the numeric character is converted to a number and the two are
added. For examples, see the table that follows.
ExampleResult
x := "A" + 1
x := "1" + 1
x := ("A" + (1 + 3))
x
equals A1 (which is a character string)
x
equals 2 (which is a number)
x
equals A4 (which is the result of a mathematical operation [1+3=4] being
converted to a character string before being concatenated to A)
x := ("A" + 1 + 3)
x
equals A13 (which is a character string because the numbers converted and not
added, due to operator precedence)
x := (1 + 3 + "A")
x
equals 4A (which is a character string because the numbers are added and then
converted to a character string, due to operator precedence)
Understanding arithmetic expressions
Arithmetic expressions are statements that represent arithmetic operations, or statements that contain two
operands that are joined by an arithmetic operator. The result of an arithmetic operation is a numeric value.
ExampleResult
x := 1 + 2
x := 3 * 3
x := "2" * 3 * 4
x
equals 3
x equals 9
x
equals 24 (because 2 is converted to a number then multiplied)
Understanding PerfectScript macros35
ExampleResult
x := "A" * 2
Error (becuase letters and numbers cannot be multiplied by each other)
Understanding relational expressions
Relational expressions are statements that represent a relational operation, or statements that contain two
operands that are joined by a relational operator. The result of a relational operation is either
Given that
ExampleResult
z := (x = 6)
z := (x = 5)
z := ("Ab" > "Bb")
z := ("Ab" != "Bb")
Given that
variable
ExampleResult
w := (x < y)
w := (x > z)
x equals 5, the following examples yield the described results.
z
equals False (because 5 is less than 6)
z
equals True (because 5 equals 5)
z
equals False (becuase Ab is less than, or comes before, Bb)
z
equals True (because Ab is not equal to Bb)
x equals "A", y equals "B", and z equals "a", the following expressions return True or False in
w.
w
equals False (becuase uppercase A is less than, or comes before, uppercase B)
w
equals True (uppercase A is greater than, or comes after, lowercase a).
True or False.
Understanding logical expressions
Logical expressions are statements that represent logical operations, or statements that contain two relational
expressions that are joined by a logical operator. The result of a logical operation equals
Given that
w.
ExampleResult
w := ((x <= y) AND (y <= z))
w := ((x = y) AND (y <= z))
w := NOT(y > z)
w := ((x != 5) AND (y != 20) _
AND (z = 20))
w := (((x = 5) AND (y = 20)) _
OR (z = 20))
w := (((x = 5) AND (y = 20)) _
OR _NOT (z = 20))
x equals 10, y equals 5, and z equals 20, the following expressions return True or False in variable
w
equals True (because both relational expressions are true)
w
equals False (because the first relational expression is false)
w
equals True (because 5 is not greater than 20)
equals True (becuase all relational expressions are true)
w
equals True (because the expression z = 20 is true)
w
equals False (because all relational expressions are false)
w
True or False.
36Using expressions in PerfectScript macro statements
Understanding bitwise expressions
Bitwise expressions are statements that represent bitwise operations, or statements that contain two operands
that are joined by a bitwise operator. The result of a bitwise operation is a numeric value.
Consider the following examples of bitwise expressions.
Bitwise operatorExample and result
Bitwise NOT (
Bitwise AND (
Bitwise inclusive OR (|)
Bitwise XOR (^)
Bitwise shift left (<<)
Bitwise shift right (>>)
Bitwise rotate left (<<<)
~)
&)
x := ~(-15)
Result: x equals 14 (complement of 1)
x := ~(-15) + 1
Result: x equals 15 (complement of 2)
x := 65535 & 535
Result: x equals 535
x := 65535 | 535
Result: x equals 65535
x := 65535 ^ 535
Result: x equals 65000
x := 65535 << 1
Result: x equals 131070
x := 65535 >> 1
Result: x equals 32767
x := -2147450881 <<< 1
Result:x equals 65535
Bitwise rotate right (>>>)
x := 65535 >>> 1
Result: x equals -2147450881
Using command statements in PerfectScript macros
A command statement consists of a macro command, which represents a single instruction (typically, an
action) in a macro.
Understanding macro commands
PerfectScript provides access to two main types of macro commands: product commands and programming
commands.
OLE object commands represent a third type of PerfectScript macro commands. Also called “a method,”
an OLE object command performs a task on an OLE object in a specific OLE Automation server. For
more information, see “Understanding OLE Automation” on page 60.
Understanding PerfectScript macros37
Product commands perform functions that let you use WordPerfect Office features in your macros. Product
commands can be specific to one WordPerfect Office application or common to all of them. Many product
commands require you to specify parameters that determine settings for dialog boxes or other application
features (such as the ruler).
Product commands that report information (that is, return a value) about the state of an application or
feature are sometimes called system variables. In WordPerfect, system variables begin with a leading
question mark (as in
EnvPaths).
in
?ColumnWidth). In Presentations, system variables begin with a leading Env (as
Programming commands perform functions that let you direct the function of a macro by controlling how
application features act and interact. For example, you can use programming commands to specify macro
conditions (see “Using conditional statements in PerfectScript macros” on page 42), specify that part of a macro
run several times (see “Using loop statements in PerfectScript macros” on page 45), invoke or jump to a specified
subroutine (see “Using calling statements in PerfectScript macros” on page 46), and so on.
You can use a product command by itself to create a basic macro that performs a simple task within a
WordPerfect Office application. For example, the following product command displays the fourth slide in the
current slideshow in Presentations:
ShowSlide(Slide: 4)
However, you must use product commands and programming commands together if you want to create a more
complex macro. For example, the following code uses the product commands
LineSpacingDlg with the programming commands If, Else, and Endif to determine which dialog box to
display in WordPerfect. (The Line Height dialog box is displayed if
Spacing dialog box is displayed if
x has any other value.)
x equals the value "A", while the Line
LineHeightDlg and
If (x = "A")
LineHeightDlg
Else
LineSpacingDlg
Endif
Understanding macro-command components
All macro commands have a name, and most macro commands have one or more parameters (which are marked
by separators). For a PerfectScript macro to work properly, its macro commands must be spelled correctly and
must include all required parameters (and the necessary separators) in the correct order.
When you create a macro by recording it (see “Recording PerfectScript macros” on page 70), the
correct syntax is automtically applied to all macro commands. However, when you create a macro by
typing code (see “Writing and editing PerfectScript macros” on page 71), you must manually apply the
correct syntax to all macro commands.
In addition, some macro commands can be used to return data from various sources. Such commands are said
to have return values.
As previously mentioned, product commands that return a value about the state of an application or
feature are sometimes called system variables.
For more information about the components of a macro command, see the following topics:
• “Understanding PerfectScript command names” on page 39
38Using command statements in PerfectScript macros
• “Understanding PerfectScript parameters” on page 39
• “Understanding PerfectScript return values” on page 41
Understanding PerfectScript command names
The name of a macro command (that is, the “command name”) indicates which feature is activated by that
command.
Sometimes, a name is all that is necessary to perform the complete action of a macro command. For example,
FileOpenDlg is a complete macro command because the name itself contains enough information to complete
the task of displaying the Open File dialog box in WordPerfect.
Understanding command-name syntax
Command names are not case-sensitive. Although many commands appear in mixed case, you can type them
entirely in uppercase or lowercase if desired.
Most command names do not contain spaces. Exceptions include programming commands that call a
subroutine, such as
Case Call or OnCancel Call.
For information about calling statements, see “Using calling statements in PerfectScript macros” on
page 46.
Understanding PerfectScript parameters
While a command name (see “Understanding PerfectScript command names” on page 39) specifies a feature,
some tasks require more information than this feature name alone can provide. To capture the settings for a
feature, some macro commands provide one or more parameters, which are passed to the macro compiler (or
between statement blocks) to carry out the desired task. For example, the WordPerfect product command
Backup() is associated with the Automatic Document Backup feature, which can be toggled by specifying a
parameter, as in
Backup(State:On!).
The type of information that is required by a parameter is represented by a data type. Each parameter accepts a
specific data type. The most common data type for programming commands is Variable (see “Understanding
PerfectScript variables” on page 10), while the most common data types for a product command are String
(which specifies sequence of characters), Numeric (which specifies a numeric value), and Enumeration (which
specifies one fixed value from a list of possible values).
In the macro-command syntax, data types are displayed in italicized text.
Parameters of data type
enumerations are identified by a trailing exclamation point (
BoxCaptionRotation provides the parameter Rotation, which provides the following enumerations:
Degrees90!, Degrees 180!, Degrees 270!, and None!.
In the following example of a WordPerfect macro command,
parameter of data type Enumeration, and it is assigned the enumeration
of type Numeric, and it is assigned a numeric value of
Enumeration provide a set list of enumerations from which to choose. These
!). For example, the WordPerfect command
Advance is the command name. Where is a
AdvanceDown!. Amount is a parameter
1.0". The resulting macro command instructs
WordPerfect to advance the insertion point down by one inch.
Advance (Where: AdvanceDown!; Amount: 1.0")
Understanding PerfectScript macros39
Understanding parameter syntax
The parameters for a macro command must be enclosed in a set of parentheses [ ()]. Inserting a space
between the command name and the left parenthesis is optional. However, using both a left parenthesis and a
right parenthesis is mandatory; omitting either parenthesis is a common error than can prevent a macro from
compiling.
Some programming commands and system variables have no parameters. Their syntax is the command
name alone. Examples include the PerfectScript command
?FeatureBar.
Pause and the WordPerfect command
Some product commands have no parameters. Their syntax is usually written with empty parentheses.
An example is the WordPerfect command
PosScreenUp ().
Using parentheses is mandatory for user-defined functions and procedures. For more information about
functions and procedures, see “Understanding subroutines” on page 46.
A parameter is separated from its value by a colon (
Each parameter ends with a semicolon (
;). When a macro command requires several parameters, they must be
:). Inserting a space between colon and value is optional.
placed in the order shown (and separated by their trailing semicolons). Inserting a space after a semicolon is
optional.
For macro commands that have a single parameter, using the trailing semicolon is optional.
If you omit an optional parameter, you must include its semicolon in the syntax to keep the parameters that
follow in their correct positions. Consider the following WordPerfect command:
Some macro statements are too lengthy to fit into a single line of macro code. If your macro editor
automatically inserts a hard return at the end of every line, you must insert an underscore character
(
_ ) at the end of each line that wraps. For information on specifying a macro editor, see “To specify
settings for editing macros” on page 67.
One way to reduce the length of a macro command is to omit parameter names. For example, the WordPerfect
command
WordPerfect command
InhibitInput (State: Off!) works the same as InhibitInput (Off!). Similarly, consider the
GraphicsLineLength (Length: Numeric), which can be written as follows:
GraphicsLineLength (Length: 2I)
or
GraphicsLineLength (2I)
40Using command statements in PerfectScript macros
Understanding PerfectScript return values
Some macro commands let you retrieve data from various sources. For example, such commands can get the
current date from the system, the current page number or document filename from an application, or a specific
value from the Windows® registry. This information is usually returned as a return value. Many programming
commands provide return values, as do some product commands.
WordPerfect returns this type of information primarily with system variables.
Handling return values
To handle a return value, you must assign it to a variable (see “Understanding PerfectScript variables” on
page 10) or use it in an expression (see “Understanding expressions” on page 9). For example, the expression
vVariable := ?Name assigns the return value of ?Name (which represents the filename of the current
WordPerfect document) to the variable
The return value of a system variable is handled in the same manner as the return value of a macro
command.
To ignore a return value, don’t handle it. For instance, some macro commands both change the state of an option
and return the previous state of that option. If you want to change the state of an option without returning its
previous state, you can ignore the return value.
Evaluating to return values
Macro commands that return values (and system variables) are said to “evaluate to” their return value. For
example, because
(2+2) evaluates to 4, you can use (2+2) in an expression rather that using 4. Similarly,
because the WordPerfect system variable
?Name in an expression rather than using the filename of the current document.
vVariable.
?Name evaluates to the filename of the current document, you can use
Consider a macro that opens a file, writes text to it, and then closes it. To close the file, you can use the
PerfectScript command
False otherwise). Because CloseFile evaluates to its return value, you can use the following syntax to both
close the file (where
If (CloseFile (FileID: xxxx))
...(statements to execute if the file was successfully closed)...
Else
...(statements to execute if the file was not successfully closed)...
EndIf
CloseFile; however, this command also returns True if the file closes successfully (and
xxxx is the ID number of the file) and check whether it closes successfully:
Return values can be handled outside of the context of a command. However, for return values of data type
Enumeration, the returned enumeration has no meaning unless it is associated with a command. For example,
the enumeration
On! has no meaning by itself, but when used in the context of a command parameter, it
indicates that that parameter is turned on. For this reason, PerfectScript evaluates return values of type
Enumeration to the name of the command, followed by a period, followed by the enumeration (that is,
command name.enumeration!).
For example, the syntax for the programming command
enumeration := Cancel (State: Enumeration)
Cancel is as follows:
Understanding PerfectScript macros41
The Cancel command determines how a macro responds to a Cancel condition. It also returns the previous
Cancel state (On! or Off!). The following example sets the Cancel state to On!, stores the current state of the
Cancel command in the variable vVariable, and types Correct in the current WordPerfect document:
Cancel (State: On!)
vVariable := Cancel ()
If (vVariable = Cancel.On!)
Type ("Correct")
EndIf
If (vVariable = "Cancel.Off!")
Type ("Not Correct")
EndIf
If the optional parameter is omitted, the Cancel state can be returned without changing it. In this scenario, the
Type command is not executed because the expression in the second If statement assumes that the
enumeration returned by the
Cancel command is a string. (Although enumerations look like strings, they are
not.)
Enumerations have numeric equivalents. In the preceding example,
to follow the above example with the WordPerfect product command
vVariable is also equal to 1. If you were
Type(vVariable), the number 1 would
be typed in the current document. The numeric equivalents of enumerations can change, so as previously
mentioned, you must use the syntax
command name.enumeration! to evaluate to return values.
Using assignment statements in PerfectScript macros
Assignment statements assign the value of an expression (see “Understanding expressions” on page 9) to a
variable (see “Understanding PerfectScript variables” on page 10). The assignment operator (
the value of a right-operand expression to a left-operand variable.
For more information about assignment operators, see “Understanding assignment operators” on
page 22.
For example, the result of the following assignment statement is that
x := "John Doe"
x equals John Doe:
The result of the following assignment statement is that y equals 5:
y := 5
The result of the following assignment statement is that z equals the result of 3 + 4:
z := 3 + 4
:= or =) assigns
Using conditional statements in PerfectScript macros
Conditional statements execute a statement (or statement block) when a specified condition is met — that is,
when an expression is true, or when a variable matches a constant.
You can use a conditional statement to present the user with a list of options.
42Using assignment statements in PerfectScript macros
Conditional statements include Case, If, and Switch. For more information about these conditions, see the
following topics:
• Understanding Case conditions
• Understanding If conditions
• Understanding Switch conditions
Understanding Case conditions
A Case condition executes a Label statement when Test (that is, a user-defined variable) matches a constant
value.
In the following example,
is called. If there is no match, then
The statement block for a Switch conditon can call a subroutine (see “Understanding subroutines” on
page 46). If
By using a
Switch condition, you can alter the sequential play of macro commands. For example, if the
Continue follows a statement block, the next statement block is automatically executed.
following pair of commands is used in a macro, the second command overrides the first (because the Paint
Brush width is set to 25 pixels and subsequently changed to 75 pixels):
If you want the macro to choose between these SetBrushWidth commands, you can use a Switch condition.
In the following example, a Paint Brush width of
Paint Brush width of
pixels is set. (The value of
75 pixels is set. Finally, if Test equals any value except 1 or 2, a Paint Brush width of 50
Test can be determined by using a programming command such as Menu or
25 pixels is set if variable Test equals 1. If Test equals 2, a
The following example contains two CaseOf statements. If variable x equals 1, a subroutine named Start is
called. If
44Using conditional statements in PerfectScript macros
x equals 2, a subroutine named Stop is called.
Switch (x)
CaseOf 1: CALL (Start)
CaseOf 2: CALL (Stop)
EndSwitch
Using loop statements in PerfectScript macros
Loop statements execute a statement (or statement block) a specified number of times until (or while) an
expression is true. When the loop ends, the macro continues to the next statement.
You can indent lines to show levels of loop statements.
Loop statements include
For, Repeat, and While. For more information about loop statements, see the
following sections:
• Understanding For loops
• Understanding Repeat loops
• Understanding While loops
Understanding For loops
A For loop uses a For-EndFor construction to execute a statement (or statement block) a specified number of
times.
In the following example,
value of
<TerminateExp> is false and the loop ends. (If <TerminateExp> is initially false, then the statements do not
<ControlVariable>. <IncrementExp> increases the value of <ControlVariable> until
<InitialValue> initializes <ControlVariable>. <TerminateExp> tests the
execute because the test is checked at the start of the loop.)
For (<ControlVariable>; <InitialValue>; <TerminateExp>; <IncrementExp>)
...statement block....
EndFor
In the following example, x is initialized to 1. The statement block executes while x is less than 5, and x is
incremented by
For(x; 1; x < 5; x + 1)
...statement block...
EndFor
1 at the end of each loop.
Similar loop statements to For are ForEach and ForNext.
Understanding Repeat loops
A Repeat loop uses a Repeat-Until construction to execute a statement (or statement block) until an
expression is true. All
Repeat statements execute at least once because the expression is checked at the end of
the loop.
In the following example, the statement block is executed until the expression
greater than or equal to
Repeat
...statement block...
Until (x >= 10)
10).
x = 10 is true (that is, until x is
However, the loop in the previous example does not end until the value of x changes to make the expression
true. In the following example, the expression
so that the loop ends when
Understanding PerfectScript macros45
x is greater than or equal to 10.
x := x + 1 is used to increment x by 1 at the end of each loop
Repeat
...statement block...
x := x + 1
Until (x >= 10)
Understanding While loops
A While loop uses a While-EndWhile construction to execute a statement (or statement block) while an
expression is true. A
While statement cannot execute unless the expression is true because the expression is
checked at the start of the loop.
In the following example, the statement block is executed while the expression
is less than or equal to
While (x <= 10)
...statement block...
EndWhile
10). If x is greater than 10, the loop does not execute.
x<= 10 is true (that is, while x
However, the loop in the previous example does not end until the value of x changes to make the expression
true. In the following example, the expression
so that the loop executes while
While (x<=10)
...statement block...
x := x + 1
EndWhile
x is less than or equal to 10.
x := x + 1 is used to increment x by 1 at the end of each loop
Using calling statements in PerfectScript macros
Calling statements involve a subroutine, which is one or more statements that are grouped as one item.
The larger a macro becomes, the more likely the need to create subroutines. Creating subroutines makes it
easier to reuse code, and makes the macro easier to read and understand.
Understanding subroutines
A subroutine consists of a statement or a statement block that is played when called by a macro. Subroutines
are useful because their statements are accessible to any part of a macro and can be called any number of times
during play.
46Using calling statements in PerfectScript macros
In the preceding example, the calling statement Call (SubExample) calls (that is, directs macro play to) the
subroutine
Call (SubExample).
Label (SubExample). The Return command directs macro play to the statement that follows
PerfectScript macros support the following types of subroutines:
• labels — act as a place holder, or marker, in a macro. For more information, see “Understanding
PerfectScript labels” on page 47.
• functions and procedures — contain one or more statements that execute when called. Functions can be used
to return a value, but procedures cannot. For more information, see “Understanding PerfectScript functions
and procedures” on page 48.
• callbacks — enable a macro to respond immediately, and in specific ways, to events. For more information,
see “Understanding PerfectScript callbacks” on page 58.
You can use subroutines to create calling statements. For more information, see “Creating calling statements
from PerfectScript subroutines” on page 58.
Understanding PerfectScript labels
A label is a subroutine that acts as a place holder, or marker, in a macro. A macro can call the label when a
certain function needs to be performed. After that function is performed, the
execution to the command that immediately follows the call to the label.
Labels in the main body of a macro can execute without being called.
Labels cannot hide macro code or macro variables.
Return command redirects
In general, macro labels are not used in structured programming unless they are needed within a
function or procedure.
Creating labels
A label is created by using the Label command, which has one parameter: the name of the subroutine. The
Label command takes no optional parameters.
Label names have the following conventions:
• They must begin with a character.
• They must consist of one or more letters or numbers.
• They are limited to 30 characters. (If a label name is longer than 30 characters, only the first 30 characters
are recognized.)
• They have an optional trailing
Labels generally include one or more statements and are followed by the commands
Calling labels
@ sign.
Return or Quit.
Label statements execute in the same way as other macro statements and do not need to be called. However, if
desired, you can call a label by using any of the following PerfectScript commands:
• Call
•Go
• Case
• Case Call
• OnCancel
• OnCancel Call
Understanding PerfectScript macros47
• OnError
• OnError Call
• OnNotFound
• OnNotFound Call
• OnDdeAdvise Call
• DdeExecuteExt
Structuring labels
The following is an example of a label:
Call( MyLabel@ )
Quit
Label( MyLabel@ )
MessageBox (nVar; ""; "The Label was called.")
Return
Understanding PerfectScript functions and procedures
Functions and procedures are subroutines that contain one or more statements that execute when called. Most
functions and procedures have parameters that receive values from a calling statement. However, some
functions and procedures have zero parameters, in which case, they perform like a
“Understanding PerfectScript labels” on page 47) except that they cannot execute unless called by the macro.
Label statement (see
The difference between functions and procedures is that functions can return a value whereas procedures cannot.
Creating functions and procedures
Functions and procedures can be placed anywhere in a macro, or in a macro-library file (see “Storing functions
and procedures in macro libraries” on page 55). Functions begin with the word
ENDFUNC, while procedures begin with the word PROCEDURE and end with ENDPROC.
FUNCTION and end with
A function or procedure cannot be defined inside another subroutine.
When you create a function or a procedure, you must name it. Function names and procedure names have the
following conventions:
• They must begin with a character.
• They must consist of one or more letters or numbers.
• They are limited to 30 characters. (If a function name is longer than 30 characters, only the first 30
characters are recognized.)
• They can (optionally) have a trailing
@ sign.
Functions accept any of the following:
•a
Return statement that has no parameters (return 0)
• a value contained in a variable that is the result of a function
• an enumerated type that asserts a
Cancel, Error, or Not Found condition
• a value contained in a variable that is the result of a function operation
Procedures accept any of the following:
•a
Return statement that has no parameters (which direct macro execution to the statement that follows
the caller of a procedure)
48Using calling statements in PerfectScript macros
•a Return statement that has one parameter (which is an enumerated type that asserts a Cancel, Error, or
Not Found condition)
Functions and procedures can include
However, a
Using variables in functions and procedures
Label statement inside a func tion must n ot have the same n ame as a function or procedure.
Label statements that are not visible outside the function.
Function variables and procedure variables are local (or “private”) to the function or procedure. A variable with
the same name as a function variable or procedure variable can be used elsewhere in the macro without conflict.
Variables are discussed, in general, in the section “Understanding PerfectScript variables” on page 10. However,
the following details apply to using variables in funtions and procedures:
• By default, variables are created as local variables. Local variables are not visible to subroutines unless
declared as part of the subroutine. (In other words, local variables created outside of a subroutine cannot be
used by that subroutine.) The reverse is also true: If a variable is declared inside a subroutine, that variable
cannot be used or accessed outside of that subroutine. (The exception to this rule occurs when a local
variable created inside a function is returned to the calling statement by using the
Return command, or
when a parameter is passed by reference.)
• Global variables can be accessed anywhere in the macro for the life of the macro. These variables can be
accessed and modified within any function or procedure. They are also visible to and can be modified by a
macro that is started by the macro that declared the global variable.
• Persistent variables, like global variables, can be accessed and modified at any time during macro execution.
The major difference between persistent variables and global variables is that a persistent variable exists
after the macro that declared it finishes execution. For example, if macro A declares a persistent variable
named
execution; if you run macro B, and macro B attempts to use
nTestVar and sets its initial value to 3, this variable is not discarded when macro A completes
nTestVar, the value of nTestVar is still 3.
To destroy a persistent variable, you must either use the
Discard command or close the Macro Facility.
Merge variables are persistent variables, so they can be used during macro execution and merge
execution.
The scope of a variable refers to the portion of a macro in which a variable is accessible. According to scope rules,
variables can be created with the same name if they do not hold the same scope. If the scope of same-named
variables is the same, the contents of the original variable are modified by the next instance of that variable.
To understand how scope affects a macro, examine the following code:
"sVariable4: " + sVariable4 + nHardReturn +
"sVariable5: " + sVariable5)
Quit
Function CreateVariable( sVariable2; &sVariable3; sVariable4 )
sVariable1 := "I'm Global, I changed"
sVariable2 := "I’m not going to change"
sVariable3 := "I finally got initialized"
sVariable4 := "I am not really the Fourth"
Return ( sVariable4 )
EndFunc
In the preceding example, the only modified values are sVariable1 and sVariable3. sVariable1 is global
sVariable3 is passed to the function by address; they are the only values that the function can “see.” The
and
other variables were not modified because they were not within the scope of the function.
In the preceding example, the variable
sVariable4 may be in question. When this variable is passed
to the function, a copy of the variable is made inside the function. This variable contains the same
content and the same name as the original
sVariable4, but it can be seen only by the function. The
content of this second variable is modified and returned, and assigned, to a new variable called
sVariable5.
Now consider the following example:
Global ( X )
X = "My name is John Doe"
DoCount()
MessageBox ( retVal; "Variable"; X )
Quit
Procedure DoCount()
x = 1
ForNext ( y; 1; 5 )
x = x * 10
EndFor
EndProc
In the preceding example, variable X would be equal to "My name is John Doe." if not declared global. The
variable
x declared inside the DoCount procedure would have been local to that procedure and would not have
modified the contents of the original variable. Such problems become very apparent in large macros that include
many variables. (This example also illustrates the need to give variables names that are meaningful.)
Use global or persistent variables only when necessary. When variables are declared as global or
persistent and are visible to all sections of a macro, they may be changed or altered in ways that lead
to unexpected behavior in your macros.
50Using calling statements in PerfectScript macros
Passing variables to functions and procedures
Sometimes, you must pass parameters to functions or procedures. There are two ways to pass parameters to
subroutines: passing variables by value and passing variables by reference.
When a variable is passed by value as a parameter to a subroutine, a copy of the variable is made in a different
location in memory under a different name.
When a variable is passed by reference as a parameter to a subroutine, the address of the variable is used to
provide direct access to that variable. In this way, you can use the original variable inside the subroutine that
you call. Using this method lets you reduce memory usage and use fewer global variables in your macro.
& operator is used when passing a variable by address. This operator is called the “Address Operator,” and
The
it tells the function or procedure to create a reference for this variable. The Address Operator is required both
in the procedure call and in the procedure parameter list.
Here is an example of passing the address of a variable to modify its value. Procedures, unlike functions, cannot
return values; however, in this case, the original value of the variable is modified by passing the variable by
address to the procedure.
nNumber := 10
ChangeNumber ( &nNumber )
MessageBox (retVal; "New Value"; "The variable nNumber has been _
modified. The new value is " + nNumber +".")
Quit
Procedure ChangeNumber( &nNum )
nNum := nNum + 45
EndProc
If the preceding macro code were compiled and run, the MessageBox would display a value of 55.
A function can return only one value. Sometimes, however, you need a function to generate two values to be
returned and used later in the macro. In the following example, two values must be returned or changed:
OriginalCount and vBMName. You can return only one value by using the Return command, so the other
value can be modified by passing the other variable by address.
By passing the variable OriginalCount by address to the CreateBookMarkName function, we can manipulate
the original value of the variable without having to return the variable. When the function receives the variable,
it does not make a copy but references the original variable declared at the beginning of the code.
Passing arrays to functions and procedures
Like normal variables, arrays can be passed to subroutines. (For more information, see “Working with arrays”
on page 18.) If you are passing the entire array, you must assign a value to each array element; any undefined
element will be identified as an error at run-time.
Arrays can be passed by address.
Consider the following example:
Declare aOldArray[10]
ForNext ( x; 1; 10 )
// initialize all elements
aOldArray[x] := x
EndFor
aNewArray[ ] := Test( aOldArray[ ] )
// aNewArray[] is assigned the returned value
Type( aNewArray[10] )
// aNewArray[10] equals 100
HardReturn()
Type( aOldArray[10] )
// aOldArray[10] equal to 10
Quit
Function Test( aTestArray[ ] )
ForNext( x; 1; 10 )
// multiply all elements by 10
aTestArray[x] := x * 10
EndFor
Return( aTestArray[ ] )
EndFunc
In the preceding example, if you precede the calling-statement parameter and the corresponding function
parameter with an ampersand (
are modified to contain the new values in
&), 100 is returned in aOldArray[10], and all of the elements in aOldArray[]
aNewArray[]. The following code illustrates this change.
52Using calling statements in PerfectScript macros
Declare aOldArray[10]
ForNext ( x; 1; 10 )
// initialize all elements
aOldArray[x] := x
EndFor
aNewArray[ ] = Test( &aOldArray[ ] )
// aNewArray[] is assigned the returned value
Type( aNewArray[10] )
// aNewArray[10] equals 100
HardReturn()
Type( aOldArray[10] )
// aOldArray[10] equal to 100
Quit
Function Test( &aTestArray[ ] )
ForNext( x; 1; 10 )
// multiply all elements by 10
aTestArray[x] := x * 10
EndFor
Return( aTestArray[ ] )
EndFunc
Calling functions and procedures
To create a calling statement from a function or procedure, you specify the name of the function or procedure
and one or more parameters that contain values passed to the function or procedure. (If there are no parameters,
empty parentheses must follow the function name or procedure name.)
The following rules apply to calling functions and procedures:
• Functions and procedures do not execute unless they are called. They can be called from within another
subroutine, or they can be called recursively (that is, they can call themselves).
• The number of parameters in a calling statement must match the number of parameters in the function or
procedure. When a function or procedure requires multiple parameters, use semicolons (
;) to separate
those parameters.
Structuring functions
The basic structure of a function is as follows:
Function MyFunction()
. . . statement block
EndFunction
The Function keyword is followed by the actual function name. Statements are added to the function, after
which the function is ended by the
Return command, as follows:
of the
EndFunc or EndFunction keyword. A function can return a value by means
Understanding PerfectScript macros53
nOriginalValue := 6
nNewValue := AddNumbers( nOriginalValue )
MessageBox( nretVal; "New Value"; "The old value was " + nOriginalValue + ". The
new value is " + nNewValue + "."; IconInformation! )
Quit
Function AddNumbers( nInputValue )
nTempValue := nInputValue + 13
Return (nTempValue)
EndFunc
In the preceding example, nOriginalValue is initialized with a value of 6. This value is passed as a parameter
AddNumbers function. The AddNumbers function adds 13 to nInputValue and stores the result in
to the
nTempValue. nTempValue is returned to the calling statement as a parameter of the Return command. The
return value is assigned to
displayed by using the
nNewValue. The values of the nOriginalValue and nNewValue variables are then
MessageBox command.
In the preceding example, the value of
function. If the
AddNumbers macro function had attempted to access nOriginalValue without
passing the value to the function, an error would have occurred. This is because
out of scope of the
AddNumbers function.
nOriginalValue had to be passed as a parameter to the
The Procedure command begins the block of code, with the actual name of the procedure following. The end
of the procedure is marked by the
placed between the
Procedure and EndProcedure commands. If a procedure requires parameters, the code is
EndProc or EndProcedure keyword. The contents of the subroutine are
54Using calling statements in PerfectScript macros
FlushRight ()
PageNumberDisplay ()
SubstructureExit ()
EndProc
In the preceding example, the CreateFooter procedure creates a footer in a document. This footer contains
the text for path and filename, the date, and a page number — all formatted by using the specified formatting
codes. The procedure does not receive any parameters.
We c ou l d m od i f y th e
CreateFooter (10)
// Calls the procedure CreateFooter with the FontSize of // 10
Quit
Procedure CreateFooter( nFontSize )
nFontSize := 16.6 * nFontSize
// This calculates the correct font size value in WP units
FooterA (Create!)
FontSize( nFontSize)
// Recalculated value used
InsertFilenameWithPath ()
Tab()
DateText ()
FlushRight ()
PageNumberDisplay ()
SubstructureExit ()
EndProc
CreateFooter procedure to accept a value for the font size:
In the preceding example, the call made by the CreateFooter command passes one value, 10, to the
procedure. This value is received into a procedure variable that is named
nFontSize. This variable can be used
and manipulated only inside the procedure. In the example, a calculation is made to determine the proper font
height in WordPerfect units, and then the variable is used by the
FontSize command. After this routine has
ended, the variable is discarded by PerfectScript.
Storing functions and procedures in macro libraries
Macro libraries contain files that store functions or procedures (or both) that can be called from another macro
and must be compiled.
The following example contains two functions. Function
returned to the caller of the function. Function
subtracted from
Function Add(x)
x := x + 50
Return (x)
Understanding PerfectScript macros55
x and returned to the caller of the function.
Subtract receives a value in another variable named x. 25 is
Add receives a value in variable x. 50 is added to x and
EndFunc
Function Subtract(x)
x:= x - 25
Return (x)
EndFunc
The Use command lets you use functions and procedures that are stored in another macro. This command
usually precedes calling statements to a macro library.
If the preceding example were saved and compiled as
called as in the following example. After function
Subtract is called, 75 is returned in variable z. The computer then beeps because the expression z = 75 is true.
Application (WP; "WordPerfect"; Default; "EN")
Use ("C:\...\LIBRARY.WCM")
z := Add(50)
z := Subtract(z)
If (z = 75)
Beep // computer beeps because z equals 75
EndIf
LIBRARY.WCM, its Add and Subtract functions could be
Add is called, 100 is returned in variable z. After function
The preceding example can be written in shortand notation, as follows:
Application (WP; "WordPerfect"; Default; "EN")
Use ("C:\...\LIBRARY.WCM")
z := Add(Subtract(50))
If (z = 75)
Beep // computer beeps because z equals 75
EndIf
Use is a non-executing statement that can occur anywhere in a macro. A macro that makes a call to a function
or procedure in another macro file must include a
Use statement that identifies the file.
A macro library that includes only function statements or procedure statements (or both) must be compiled like
any macro file. PerfectScript automatically compiles uncompiled libraries. Macro execution stops if the macro
library file will not compile.
Many programmers create library files that contain just functions and procedures that may be used with other
macros. These functions and procedures are generic enough to be applicable to many different macros.
Here is an example of a macro that uses a function from another macro:
56Using calling statements in PerfectScript macros
Library.wcm (macro library that contains the following code)
Function GetMyDefaultDirectory()
Return ( ?PathDocument )
EndFunc
If one macro “uses” another macro, the second macro becomes a dependent of the main macro. If you want to
deploy the main macro throughout your organization or send it to a customer, You must include the second
macro.
Macro files included by using multiple
Use commands are searched from beginning to the end of the macro.
Thus, a parent macro always calls the first occurrence of a function or procedure with the same name in different
Use files. Consider the following example:
Macro1
Use( "Library1.wcm" )
Use( "Library2.wcm" )
vDefDir := GetMyDefaultDirectory()
MessageBox ( retVal; "Docs Directory";
vDefDir" )
Quit
Library1.wcm (contains)
Function GetMyDefaultDirectory()
Return ( ?PathDocument )
EndFunc
Library2.wcm (contains)
Function GetMyDefaultDirectory()
Return ( ?PathCurrent )
EndFunc
In the preceding example, the library function called by the macro is Library1.wcm because it is the first macro
library included by
Macro1.
When a macro uses a subroutine in a macro library, playing that macro incurs an error if the syntax of the call
to the subroutine is incorrect. Using a function prototype or procedure prototype forces the compiler to check
the parameter count of a function or procedure in a macro library; if the syntax is incorrect, a compiler error
occurs.
The prototype directs the compiler to validate the syntax of a function or procedure. Creating a prototype helps
you keep track of the parameters of a function or procedure. Place prototypes at the beginning of your macro,
as in the following example:
Function Prototype Check(nBeep; HdReturn)
HdReturn := NTOC(0F90Ah)
x := 4
nBeep := 1
While(x = 4)
Understanding PerfectScript macros57
BEEP
x := Check(nBeep; HdReturn)
nBeep := nBeep + 1
EndWhile
MessageBox( retVal; "RETURN"; "The value of variable vStatus (" + x _
+ ") is returned to variable x, which ends the loop."; _
IconExclamation!)
Function Check(nBeep; HdReturn)
MESSAGEBOX(vStatus; "FUNCTION EXAMPLE"; "Beeps: " + nBeep + _
HdReturn + HdReturn + "Choose Retry to beep again." + HdReturn; _
IconInformation! | RetryCancel!)
RETURN(vStatus)
EndFunc
Understanding PerfectScript callbacks
Callbacks are special functions that enable a macro to respond immediately, and in specific ways, to events.
When a macro executes a callback routine, the macro system automatically creates variables that are accessible
to that callback. The callback can access the parameter array for information about the callback event, and the
callback can place its return value (if any) in the return variable.
The parameters for a callback are placed into a global array variable that has the same name as the
callback label. Any return value for the callback routine is placed in a (non-array) global variable that
has the same name as the callback label. For example, parameters would be passed to callback routine
'MsgHandler' in an array called 'MsgHandler[ ]', and any return value would be placed into a
variable called
'MsgHandler'.
PerfectScript currently supports three types of callbacks, all of which are discussed in greater detail in the
“Support for callback entries” topic in the PerfectScript Command Reference section of the Macro Help
(psh.chm):
• product-command callbacks
• dialog-box callbacks
• message-box callbacks
Perhaps the most useful of these callback types is the dialog-box callback, which lets the macro gather
information from an active dialog box (rather than waiting until the dialog box is closed to gather that
information). For more information on dialog-box callbacks, see “Setting up callbacks for PerfectScript dialog
boxes” on page 96.
Creating calling statements from PerfectScript subroutines
You can create calling statements by using PerfectScript commands, such as the following:
•
Call — calls the specified subroutine. For more information, see “Using the Call command in calling
statements” on page 59.
58Using calling statements in PerfectScript macros
• Go — jumps to the specified subroutine. For more information, see “Using the Go command in calling
statements” on page 59.
Case or Case Call — creates a conditional statement that tests for matching expressions, and calls a label
•
if a match is found. For more information, see “Understanding Case conditions” on page 43.
For more information about these (and other) PerfectScript commands, please see the PerfectScript
Command Reference in the Macro Help (psh.chm).
Using the Call command in calling statements
The Call command has one parameter, which is the name of a subroutine to call. The Return command directs
macro execution to the statement that follows
Return directs macro execution to the first statement after Call(ExSub).
Call(ExSub) directs macro execution to Label(ExSub), where the statement block
Using a subroutine name to form a calling statement performs the same action as creating a Call statement
that specifies that subroutine name as a parameter. For example, a function or procedure that is named
If the second example calls a function, you can assign a return value to a variable with a statement such as the
following:
x := InitializeVariables (<Parameter>;<Parameter>)
For information about return values, see “Understanding PerfectScript return values” on page 41.
For information about variables, see “Understanding PerfectScript variables” on page 10.
Using the Go command in calling statements
The Go command has one parameter, which is the name of a subroutine to which to jump. Macro execution
continues from the point of the subroutine and does not return (so statements between
do not execute).
In the following example,
executed.
Go (ExSub)
...other statements...
Label (ExSub)
...statement block...
Return
Understanding PerfectScript macros59
Return ends a macro or directs macro execution to the statement that follows a Run command.
Go(ExSub) directs macro execution to Label(ExSub), where the statement block is
Return ends the macro.
Go and the subroutine
Using comment statements in PerfectScript macros
Comment statements contain notes and other information that do not affect macro play. You can use comment
statements to explain the purpose of your macro, describe its components, or to prevent a statement from
playing.
A comment statement can consist of a single line of text or instead span several lines of text. However, the syntax
for a single-line comment statement is different from that of a multi-line comment statement:
• single-line comment statement — begins with
• multi-line comment statement — begins with
// and ends with a hard return
/* and ends with */
Accessing external applications in PerfectScript macros
PerfectScript provides the following advanced features, which let macros access applications outside of
WordPerfect Office:
• OLE Automation — lets PerfectScript control applications that support OLE. For more information, see
“Understanding OLE Automation” on page 60.
• Dynamic Data Exchange (DDE) — lets PerfectScript control applications that support DDE. For more
information, see “Understanding Dynamic Data Exchange (DDE)” on page 62.
Understanding OLE Automation
PerfectScript can send commands that control WordPerfect, Quattro Pro, and Presentations. However,
through a Windows-standard interface known as OLE Automation, PerfectScript can send commands that
control other OLE-enabled applications, which are called OLE Automation servers. For this reason,
PerfectScript is called an OLE Automation controller.
OLE Automation servers define OLE Automation objects, which have names that are registered with Windows.
(For information about the OLE Automation objects that are defined for an application, refer to the
manufacturer’s documentation for that application.)
OLE Automation objects can have methods and properties.
A method is a command or function that performs an action on an object. Many methods, like product
commands, have parameters and return values. Here is a sample method for the OLE Automation object
Excel.Application:
Worksheets ().Activate
A property is an object value that can be retrieved and set. Many properties have parameters and return values.
Unlike WordPerfect system variables, many properties can be set by placing the property name on the left side
of an assignment statement (see “Using assignment statements in PerfectScript macros” on page 42). Properties
can take parameters when being retrieved (similarly to a method call) or when being set. Here is a sample
property for the OLE Automation object Excel.Application:
ActiveSheet.Name
IMPORTANT: You must set optional parameters when using OLE Automation.
60Using comment statements in PerfectScript macros
Working with OLE Automation objects
Before an OLE Automation object can be used in a PerfectScript macro, the Object statement must be used.
Object statement is similar to the Application statement for products: It defines an object-prefix
The
variable that is used to call methods and to retrieve and set object properties. The name of the object is also
specified, along with information about whether this prefix is to be used as the default object for non-prefixed
methods and properties.
The object-prefix variable that is specified in the
Object statement identifies a variable that contains an instance
handle to the object at run-time. As a variable, this prefix can be used in many places where most, but not all,
other macro variables can be used. For example, the macro language operators
+ and - cannot be used with
object variables, and automatic type conversions are not defined for object variables. Object variables can be
assigned to other object variables of the same type, and they can be passed as parameters to user-defined macro
routines.
As with other macro variables, object variables exist at run-time in a specific macro variable pool. You can specify
this pool by using
Declare, Local, Global and Persist statements (see “Understanding PerfectScript
variables” on page 10). If the object variable is not specified, it exists in the local variable pool (unless
PersistAll is in effect, in which case the object variable exists in the persistent variable pool).
Before making a call to the methods for an object, and before retrieving or setting the properties for an object,
an instance handle to a specific object must be obtained through the
GetObject statement. These statements return an instance handle to a specific instance of an object. Because
CreateObject statement or the
many OLE Automation servers support multiple instances of the objects they define, an instance handle to a
specific object must be obtained to distinguish instances of the same object. Multiple object variables can be
created, and multiple instances can be obtained if the OLE Automation server supports multiple instances.
After getting an instance handle, an object variable is said to be connected to the OLE Automation server. Like
other variables, the
Exists statement can be used on object variables to determine whether an object variable
exists and, if so, which variable pool it exists in. Even if an object variable exists, it may not be currently
connected to the OLE Automation server, but this connection information can be obtained from the
ObjectInfo command.
When an instance of an OLE Automation object is no longer needed, the connection can be terminated by using
the
Discard statement. Variables for OLE Automation objects, like other variables, are automatically discarded
when the macro terminates or when the user-defined routine in which the variable is defined ends. This
discarding automatically disconnects the object from an OLE Automation server (if connected to one).
After an object is connected to its OLE Automation server, the methods and properties of that object can be
accessed by prefixing the method name or property name with the variable name for the OLE Automation
object followed by a period (
in the
Object statement, or specified in a With statement), the object-prefix variable can be replaced by two
leading periods (
..). Leading periods are necessary to inform the macro compiler that the method name being
.). If the OLE object variable is the default object variable (specified by Default!
called is not the name of a user-defined macro routine but the method name (or property name) of the current
default OLE Automation object.
A macro can use more than one application product and OLE Automation object. Commands to the
non-default application or OLE Automation object require a prefix, which is specified in a PerfectScript
Application or Object statement. In the example A1.A boutDlg (), the prefix A1. tells the
compiler to use the application or object that is assigned
A1 in a PerfectScript Application or Object
statement.
Understanding PerfectScript macros61
To establish a new default object for a localized block of code, you can use a With-EndWith compound
statement. The object-prefix variable is specified in the
properties preceded by two periods (..) until the
The
NewDefault statement can be used to establish a new default object-variable prefix for the remainder of a
macro (or until the macro encounters another
For more information
EndWith statement, are assumed to be references to that object.
NewDefault statement).
With statement; all statements to access methods, and
For more information about OLE Automation, please see the following:
• PerfectScript support: the topic “Support for OLE Automation” in the PerfectScript Command Reference
section of the Macro Help (psh.chm)
• WordPerfect support: “Using OLE Automation” and “Understanding OLE Automation” in the main
WordPerfect Help (wpwp.chm)
• Quattro Pro support: “Using OLE Automation” in the main Quattro Pro Help (qp.chm)
See also “Using the WordPerfect Office Software Development Kit (SDK)” on page 63.
Understanding Dynamic Data Exchange (DDE)
Dynamic Data Exchange (DDE) Execute is a Windows feature that enhances product integration by allowing
applications to instruct each other to perform specific tasks (that is, to execute commands). For example, you
can use the DDE Execute feature to create macros in WordPerfect that send commands to control other
Windows applications that accept DDE Execute strings.
WordPerfect, Quattro Pro, and Presentations are DDE servers, and they provide support to DDE clients
through the PerfectScript language.
An instance of DDE-based communication between two applications is called a DDE conversation. WordPerfect,
Quattro Pro, and Presentations each handle DDE conversations in their own way.
For more detailed information about using DDE, see the WordPerfect Office Software Development
Kit (SDK), which is included in the Professional Edition of WordPerfect Office. For more information,
see “Using the WordPerfect Office Software Development Kit (SDK)” on page 63.
Understanding DDE conversations for WordPerfect
WordPerfect can act as a server for DDEExecute commands.
To access the PerfectScript-based product commands for WordPerfect, the DDE client must initiate a DDE
conversation by using
Understanding DDE conversations for Quattro Pro
WPWin15_Macros as the service name and Commands as the topic name.
Quattro Pro can act as a server for DDERequest commands.
To access request topics, application status, or properties from Quattro Pro, the DDE client must initiate a DDE
conversation by using
QPW as the service name and System as the topic name.
To read and write to spreadsheet cells, or to execute PerfectScript-based product commands for Quattro Pro,
the DDE client must initiate a DDE conversation by using
QPW as the service name and the path and file of an
open notebook as the topic name.
62Accessing external applications in PerfectScript macros
Understanding DDE conversations for Presentations
Any eligible Windows application can use the DDE Execute feature to control Presentations. To begin, the DDE
client must initiate a DDE conversation by using
Presentations as the service name and Command as the topic
name. Before terminating the conversation, the client can send DDE Execute strings that include PerfectScriptbased product commands for Presentations (provided that those commands do not contain variables or
expressions).
Eligible Windows applications can also send commands to Presentations as a DDE Request item. In this
scenario, Presentations returns an ANSI® text string that represents the return value of the command.
The DDE client must send DDE Execute strings and DDE Request items in ANSI text format. If Presentations
returns an error, the DDE client can determine what went wrong by sending a DDE Request item for
LastCmdError; Presentations then returns an ANSI text string that contains a three-digit error code and a
description of the error.
Learning more about PerfectScript macros
If you want to learn more about PerfectScript macros, you can consult the WordPerfect Office Software
Development Kit (SDK) or the Corel website.
This section contains the following topics:
• Using the WordPerfect Office Help
• Using the WordPerfect Office Software Development Kit (SDK)
Using the WordPerfect Office Help
The main Help files for WordPerfect, Quattro Pro, and Presentations contain additional information on
PerfectScript macros.
•WordPerfect Help (wpwp.chm): see the PerfectScript topics in “Using macros and other automation
features”
• Quattro Pro Help (qp.chm): see the PerfectScript topics in “Using macros”
• Presentations Help (wppr.chm): see “Working with PerfectScript macros”
Using the WordPerfect Office Software Development Kit (SDK)
The WordPerfect Office Software Development Kit (SDK) is a set of tools that lets you customize WordPerfect
Office applications for commercial or business use. The WordPerfect Office SDK includes documentation,
samples, and various tools and utilities.
The WordPerfect Office SDK is included with certain editions of WordPerfect Office.
Understanding PerfectScript macros63
64Learning more about PerfectScript macros
Getting started with PerfectScript macros
Now that you understand the basics about PerfectScript, you are ready to get started with macros by learning
how to use the PerfectScript utility.
This section contains the following topics:
• “Using the PerfectScript utility” on page 65
• “Specifying PerfectScript settings” on page 66
Using the PerfectScript utility
To get started with PerfectScript macros for WordPerfect Office, you can use the PerfectScript utility.
WordPerfect, Quattro Pro, and Presentations provide a To o l s ` Macro menu, which lets you work
with macros from directly within the application. (WordPerfect also provides a To o l s ` Te m p l a t e macro menu, which lets you work with template macros and QuickMacros from directly within
WordPerfect.) For information about working with macros from directly within WordPerfect,
Quattro Pro, or Presentations, please see the Help file for the application.
The PerfectScript utility provides the following tools for creating PerfectScript macros:
• Command Browser — displays a list of all available programming commands for PerfectScript, as well as
all available product commands for WordPerfect, Quattro Pro, and Presentations.
• Dialog Editor — lets you create dialog boxes for your macros.
The PerfectScript utility provides context-sensitive Help for many of its controls, as well as Help for all of the
macro commands in its Command Browser.
You can quit the PerfectScript utility when you have finished using it.
This section contains the following procedures:
• To start the PerfectScript utility
• To display the Command Browser
• To display the Dialog Editor
• To access context-sensitive Help for the PerfectScript utility
• To access Help for a macro command
• To quit the PerfectScript utility
To start the PerfectScript utility
• On the Windows taskbar, click Start ` All programs ` WordPerfect Office X6 ` Utilities `
PerfectScript.
To display the Command Browser
• In the PerfectScript utility, click Help ` Macro Command Browser.
For information about using the Command Browser to create macros, see “Writing and editing
PerfectScript macros” on page 71.
Getting started with PerfectScript macros65
To display the Dialog Editor
• In the PerfectScript utility, click To o l s ` Dialog Editor.
The Dialog Editor works only with macros that are in WordPerfect format. For this reason, you can
open the Dialog Editor from directly within WordPerfect by clicking Dialog Editor on the Macro
toolbar when editing a macro.
For information about using the Dialog Editor, see “Creating UI for PerfectScript macros” on page 79.
To access context-sensitive Help for the PerfectScript utility
•Click (or press Shift + F1), and then click the desired control.
To access Help for a macro command
• In the Command Browser, right-click the desired command.
To quit the PerfectScript utility
•Click File ` Exit.
Specifying PerfectScript settings
From within the PerfectScript utility, you can specify various PerfectScript settings.
This section contains the following procedures:
• To specify general macro settings
• To specify settings for compiling macros
• To specify settings for debugging macros
• To specify settings for editing macros
• To specify settings for playing macros
• To specify settings for recording macros
• To specify settings for the PerfectScript toolbar
To specify general macro settings
1 Click To o l s ` Settings, and then click the General tab.
2 Do any of the following:
• Specify a default macro folder.
• Enable the Use enhanced file dialogs check box if you want to view detailed dialog-box information.
• Enable the Display icons in system tray check box if you want to display macro icons in the Windows
system tray.
• Enable the Check file associations on startup check box if you want to check file associations at
startup.
Click Reset all to defaults to return all settings to their original state.
66Specifying PerfectScript settings
To specify settings for compiling macros
1 Click To o l s ` Settings, and then click the Compile tab.
2 Enable any of the following check boxes:
• Show progress
• Include debug information
• Warn when using unsupported features
• Generate listing file
To specify settings for debugging macros
1 Click To o l s ` Settings, and then click the Debug tab.
2 Do any of the following:
• Enable the Invoke Debugger on macro start check box, if you want.
• Enable the Invoke Debugger on errors check box, if you want.
• Enable the Debugger event logging check box, if you want.
• In the Animate settings area, enable the desired ‘Run to’ option, and specify the desired delay (in
seconds).
Debug, a menu item for the Windows shell, appears on the context menu for the desktop icon of any
macro.
To specify settings for editing macros
1 Click To o l s ` Settings, and then click the Edit tab.
2 Specify the path and filename of the macro editor that you want to use.
3 Specify a file format that is compatible with the macro editor that you’ve chosen.
You must specify a macro editor if you want to edit macros.
Some macro statements are too lengthy to fit into a single line of macro code. If your macro editor
automatically inserts a hard return at the end of every line, you must insert an underscore character
_ ) at the end of each line that wraps.
(
Although you can use any ASCII-based text editor to edit macros, some editors offer special features.
For example,
• When you use Notepad, you can create a macro just by specifying its filename.
• When you use WordPerfect, you can use the PerfectScript Command Inserter (on the Macro
toolbar) to insert macro commands into your macros or to edit existing macro commands.
To specify settings for playing macros
1 Click To o l s ` Settings, and then click the Play tab.
2 Do any of the following:
• Specify a value in the Play repeat count box.
• Enable the Security for JavaScript® check box, if you want.
• Enable the Show elapsed time check box, if you want.
Getting started with PerfectScript macros67
To specify settings for recording macros
1 Click To o l s ` Settings, and then click the Record tab.
2 Do any of the following:
• From the Script language list box, choose the script language that you want to use.
• From the File format list box, choose the file format in which you want to save macros. (This file format
must be compatible with the macro editor that you specify on the Edit page.)
• From the Parameters per line list box, choose One or Multiple to set the number of parameters in each
macro line.
• In the Maximum line length box, specify a maximum line length for macro text.
• Enable the Named parameters required check box if you want to use only named parameters in your
macros.
• Enable the Record product prefixes on all commands if you want to insert product prefixes in your
macros.
To specify settings for the PerfectScript toolbar
1 Click To o l s ` Settings, and then click the To o l b a r tab.
2 Do any of the following:
• Enable the Use large icons on toolbar buttons check box, if you want.
• Enable the Show text on toolbar buttons check box, if you want.
• Assign macros to the available toolbar buttons, if you want. The macro buttons on the PerfectScript
toolbar can be configured to play any desired macro.
The PerfectScript toolbar appears as a flat toolbar, similarly to other toolbars in WordPerfect Office.
68Specifying PerfectScript settings
Creating PerfectScript macros
Now that you know how to use the PerfectScript utility, you are ready to create PerfectScript macros.
This section contains the following topics:
• “Migrating legacy PerfectScript macros” on page 69
• “Recording PerfectScript macros” on page 70
• “Writing and editing PerfectScript macros” on page 71
• “Compiling PerfectScript macros” on page 74
• “Playing PerfectScript macros” on page 76
• “Making PerfectScript macros user-friendly” on page 77
Migrating legacy PerfectScript macros
You can use the PerfectScript utility to migrate PerfectScript macros from previous versions of WordPerfect
Office to a later version of the software.
With each new version of WordPerfect Office, some commands are added, some commands are
changed, and some commands become obsolete and are removed altogether. Because of such changes,
macros from earlier versions of WordPerfect Office might need minor corrections when migrated to a
later version of the software.
This section contains the following procedures:
• To migrate a legacy PerfectScript macro
Converting non-PerfectScript macros to PerfectScript format
You may also be able to use the migration process to convert a non-PerfectScript macro to PerfectScript format.
(For example, if you record a macro in a non-PerfectScript language — JavaScript, Microsoft Visual Basic, Corel
SCRIPT™, or Borland® Delphi®, as explained in “To specify settings for recording macros” on page 68 — you
may subsequently want to convert that macro to PerfectScript format.) However, you must be sure to take
certain precautions when converting macros.
First, be sure to review each variable, label, procedure, and function name in your existing macro, and change
any names that have become reserved words. Each new version of WordPerfect Office adds PerfectScript
keywords, which are reserved words that cannot be used as variable or label names in macros; in addition, the
names of all macro commands are considered reserved words because they cannot be used as variable or label
names. For more information on reserved words, please see the “Reserved words” topic in the PerfectScript
Command Reference section of the Macro Help (psh.chm).
Next, be sure to review any arrays in your existing macro (see “Working with arrays” on page 18). Please note
the following:
• You can pass array slices to repeating parameter groups of commands. In early versions of PerfectScript, you
could pass only entire arrays. Empty slices can now be specified, if the end index is less than the first index.
• Negative array indexes can be used in array slices. If negative, the index is considered to be end-relative,
not start-relative. An index of
element, and so on.
[-1] represents the last element, [-2] represents the second-to-last
Creating PerfectScript macros69
• You can assign non-arrays to arrays, and arrays to non-arrays. If an array is assigned to a non-array variable,
the assignment is actually made to the array variable with the same name as the non-array variable, and the
non-array variable is left untouched. If a non-array is assigned to an array variable, the non-array value is
converted into a single element array with that value, and it is assigned to the array variable.
• Non-array values and arrays can be combined by using the operators
elements will be ignored and skipped over.
Non-array values and arrays can also be combined by using the following operators (although
undefined array elements will be ignored and skipped over):
• unary operators — for information, see “Understanding PerfectScript operators” on page 21.
• arithmetic operators — for information, see “Understanding assignment operators” on
page 22.
• relational (comparison) operators — for information, see “Understanding relational operators”
on page 24.
• logical operators — for information, see “Understanding logical operators” on page 26.
• bitwise operators — for information, see “Understanding bitwise operators” on page 28.
• JavaScript operators — for information on specifying JavaScript as the macro-recording
language, see “To specify settings for recording macros” on page 68.
Finally, when converting a native QuattroPro macro to PerfectScript format, you may want to know how to
manually convert the syntax of each Quattro Pro command. For more information, see “Understanding
Quattro Pro macros” on page 129.
^^ or \. However, undefined array
To migrate a legacy PerfectScript macro
1 In the PerfectScript utility for the later version of WordPerfect Office, click File ` Play.
2 Select the legacy macro that you want to migrate.
3 Specify a path and filename for the migrated macro, and then click Play.
The macro is compiled for use with the later version of WordPerfect Office.
4 Make note of any errors that are encountered by the macro compiler, and make the necessary fixes to the
macro.
For tips on resolving macro-compilation errors, see “Troubleshooting macro-compilation errors” on
page 74.
Recording PerfectScript macros
You can create a basic PerfectScript macro by using the PerfectScript utility to record keyboard actions in
WordPerfect, Quattro Pro, or Presentations. Keyboard actions are actions that you perform by using the
keyboard — for example, typing text or saving a file.
You cannot record mouse actions. However, you can use the keyboard to position the cursor by
pressing an arrow key or a navigation shortcut key.
You cannot record some actions at all. However, you may be able to manually code such actions by
using a macro editor (see “Writing and editing PerfectScript macros” on page 71).
You can also record macros from directly within WordPerfect, Quattro Pro, or Presentations. For
information, please see the Help file for the application.
70Recording PerfectScript macros
You can also record template macros and QuickMacros from directly within WordPerfect. For
information, please see the Help file for WordPerfect.
When you record a PerfectScript macro, you record the results of your actions rather than your actual actions.
For example, if you record a macro that changes the top margin of a page to 2 inches in a WordPerfect
document, PerfectScript records the WordPerfect product command
MarginTop(MarginWidth:2.0") rather
than the step-by-step method that you used to change the margin. The correct PerfectScript syntax (see
“Understanding macro commands” on page 37) is automatically applied to all recorded product commands; for
this reason, recording a macro helps you avoid typos and similar errors that can occur when manually coding
macros.
Only product commands can be recorded. If you want to include programming commands (or complex
functions such as assignments or loops) in a macro, you must manually code them. For information, see
“Writing and editing PerfectScript macros” on page 71.
This section contains the following procedures:
• To record a PerfectScript macro
To record a PerfectScript macro
1 Open the desired WordPerfect Office application.
2 In the PerfectScript utility, click File ` Record.
3 Type a name for the macro, and then click Record.
4 Switch to the WordPerfect Office application, and then perform the keyboard actions that you want to
record.
Although you cannot record mouse actions, you can use the keyboard to position the cursor by pressing an
arrow key or a navigation shortcut key.
5 When you have finished recording the macro, click File`Stop in the PerfectScript utility.
When you record a macro, the PerfectScript utility automatically records the
Application command
for the appropriate WordPerfect Office application. This command indicates the application to which
the macro belongs.
Some actions cannot be recorded. However, you may be able to manually code these actions by using
a macro editor (see “Writing and editing PerfectScript macros” on page 71).
If you need to stop recording temporarily (for example, to locate a feature or to experiment with the
effect of a feature before you record the command), click File `Pause in the PerfectScript utility. Click Pause again to resume recording the macro.
You can specify the settings to use when recording macros. For information, see “To specify settings
for recording macros” on page 68.
Writing and editing PerfectScript macros
If you prefer to write (rather than record) a PerfectScript macro, you can do so by using a macro editor — or
even by typing in a blank document. Manually coding a PerfectScript macro requires an understanding of both
the PerfectScript language and the principles of computer programming.
Creating PerfectScript macros71
A macro editor, as its name implies, lets you edit the code for an existing macro. You can edit a macro if you
want to change how that macro operates.
If you choose WordPerfect as your macro editor, you can easily insert PerfectScript macro commands into your
macro code by using the Command Inserter feature of the Command Browser. The Command Inserter feature
lets you choose macro commands and parameters from the provided lists and then insert the resulting syntax
into your macro code. Using the Command Inserter saves you time and helps you avoid typos and similar errors
that can occur when manually coding macros.
If you choose WordPerfect as your macro editor, you must disable the SmartQuotes feature. To disable
SmartQuotes in WordPerfect, click To o l s ` QuickCorrect™, click the SmartQuotes tab, and then
disable the Use double quotation marks as you type check box.
If you do not choose WordPerfect as your macro editor, you must be sure to apply the correct syntax
to all the macro commands that you type. For information about macro-command syntax, see
“Understanding macro commands” on page 37.
This section contains the following procedures:
• To write a PerfectScript macro
• To edit a PerfectScript macro
• To insert a macro command into PerfectScript macro code
Formatting PerfectScript macros
If you want to improve the readability of a macro, you can format it to include tabs, spaces, and even font styles
or other text-appearance changes. Formatting a macro does not affect how it works.
For example, WordPerfect records the following macro in this default format:
However, you can type spaces between components and blank lines between tasks, as follows:
PosDocBottom()
Type ("Sincerely")
HardReturn()
HardReturn()
HardReturn()
72Writing and editing PerfectScript macros
HardReturn()
Type ("Ms. Sharon Openshaw")
HardReturn()
Type ("Vice President, Marketing")
To write a PerfectScript macro
1 Type the macro code in a macro editor or in a blank document.
2 Save the macro as a file with a .wcm extension.
You can specify the settings to use when writing macros in a macro editor (see “To specify settings for
editing macros” on page 67).
To edit a PerfectScript macro
1 In the PerfectScript utility, click File ` Edit.
2 Select the macro that you want to edit, and then click Edit.
If necessary, click Convert to convert the macro for editing.
3 Make the desired changes to the macro, and close the macro editor.
In Windows, you can access the Edit command for a macro by right-clicking that macro.
You can specify the settings to use when editing macros (see “To specify settings for editing macros”
on page 67).
To insert a macro command into PerfectScript macro code
1 In the macro code, click where you want to insert a macro command.
2 In the PerfectScript utility, click Help ` Macro Command Browser.
3 From the Command type list box, choose the type of command that you want to insert.
4 In the Commands list, double-click the command that you want to insert.
5 In the Parameters list, double-click the parameter that you want to insert.
If the parameter has enumerations, double-click the desired enumeration to insert both the parameter and
its enumeration.
6 Repeat step 5 for each additional parameter.
7 Click Return values if you want to return value enumerations for commands that have enumerations as
return values.
8 If desired, manually edit the command in the Command edit list box.
9 Click Insert to copy the command from the Command edit box and insert it into the macro code.
You can use the Command Inserter feature only when using WordPerfect as your macro editor. For
information about choosing a macro editor, see “To specify settings for editing macros” on page 67.
For most macro commands, a default value is passed when an optional enumeration parameter is
omitted — and in some cases, omitting an optional enumeration parameter performs a different
Creating PerfectScript macros73
function altogether. In the Command Browser, any default enumeration values for a parameter are
displayed in bold text in the Parameters list.
For some macro commands, the default parameter value is a combination of enumerations. In this
scenario, several enumerations may be defined as synonyms that have the same value; in the Command
Browser, any such enumerations are highlighted.
You can display Help for any macro command in the Command Browser by right-clicking that
command in the Commands list.
Compiling PerfectScript macros
To create a functioning macro from macro code, you must use a “compiler.” PerfectScript macros are
automatically compiled when they are recorded or played, but they can be manually compiled at any time by
using the PerfectScript utility.
You can also compile macros from directly within WordPerfect or Presentations. For information,
please see the Help file for the application.
This section contains the following procedures:
• To compile a PerfectScript macro
Understanding compilers
In machine (computer) language, every word is a binary numeral that consists of zeros and ones. Consider the
following examples:
• In binary notation, the first three letters of the alphabet are 1000001, 1000010, and 1000011.
• The binary result of 4 + 5 is 1001.
Working with binary numerals can be awkward, so English-based programming languages (such as Basic,
Pascal, and C) were designed to simplify the process of writing programs. A programming language is used to
write program code in an editor or word processor, and that program code is then saved as a source file.
However, computers can execute only object files, not source files. For this reason, a program compiler is
required to create an object file by making a copy of the source file and translating that copy into machine
language.
Macro languages are similar to programming languages. A macro language (such as PerfectScript) is used to
write macro code in an editor or word processor, and that macro code is then saved as a source file. However,
rather than create a separate object file from the source file, a macro compiler creates an object and saves it in a
hidden area of the source file. This hidden object is destroyed when the source file is edited and regenerated
when the source file is recompiled.
A macro is therefore a compiled source file that contains instructions that are executed when that macro is
played. The PerfectScript macro compiler is used to compile or “translate” PerfectScript macro code into a usable
format for WordPerfect Office applications.
Troubleshooting macro-compilation errors
The PerfectScript macro compiler is useful for troubleshooting problems with your PerfectScript macros. When
the compiler locates an error, it displays a dialog box that contains general information about the problem.
However, the compiler can make only a best guess as to what a macro is intended to accomplish; as a result, the
compiler may direct you to a problem rather than specifically identify that problem.
74Compiling PerfectScript macros
If you receive an error message while compiling a macro, you can continue the macro-compilation process if you
want to check for additional errors, or you can cancel the macro-compilation process altogether. In either case,
the macro cannot be played until you correct all errors and successfully compile the macro.
The following syntax errors can cause a macro-compilation error:
• A command name is misspelled
• A semicolon is missing between macro-command parameters
• A comma, instead of a semicolon, is used between macro-command parameters
• A parenthesis is missing
• A (double) quotation mark is missing
• A (double) quotation mark is inserted by using the SmartQuotes feature in WordPerfect
• A macro command is missing from a conditional statement
• A macro command is missing from a loop statement
• A calling statement is undefined
In addition, the following conditions can cause a macro-compilation error:
• No “return” statement is found in the body of a user-defined function. In this case, a
return (0)
statement is generated.
• A “return” statement with no return value is found in the body of a user-defined function. In this case, a
value of
0 is returned.
• The macro appears to be empty when compiled. This issue can occur when a previously compiled macro
has its source removed; compiling such a macro destroys the existing (compiled) macro object.
• An obsolete or unsupported feature is found in a macro during compilation. These warnings can be safely
ignored to produce a successful macro — they serve as reminders only. Warnings are displayed when an old
EN English synonym is used in the
Application statement (US, UK, CE, OZ), or when an obsolete or
unsupported command, enumeration, or parameter is used.
When correcting macro-compilation errors, work through the macro code from beginning to end, and
focus on the errors for which the solution seems most apparent. Leave the errors with less apparent
solutions until later — some of these errors may be corrected by resolving the more obvious errors.
To compile a PerfectScript macro
1 In the PerfectScript utility, click File ` Compile.
2 Select the macro that you want to compile, and then click Compile.
You can also
Cancel the compilation of a macroIn the Compile progress dialog box, do one
of the following:
•Click the Cancel button.
• Press Enter.
If you want to compile a legacy macro or a non-PerfectScript macro, you must first convert it to the
current PerfectScript format. For information, see “Migrating legacy PerfectScript macros” on page 69.
When a macro is compiled, warnings are displayed for any labels or routines that are not defined by
that macro. However, the compiled macro will function correctly if it calls another macro that defines
those labels and routines.
Creating PerfectScript macros75
In Windows, you can access the Compile command for a macro by right-clicking that macro.
You can specify the settings to use when compiling macros. For information, see “To specify settings
for compiling macros” on page 67.
Playing PerfectScript macros
You can perform the operations that are specified in a PerfectScript macro by using the PerfectScript utility to
play that macro.
When you play a PerfectScript macro, the PerfectScript utility determines which application is
associated with that macro. The PerfectScript utility then checks the registry for the path to the EXE
file for the application. If that path is not in the registry, you are prompted to specify the location of
that EXE file.
You can also play macros from directly within WordPerfect, Quattro Pro, or Presentations. For
information, please see the Help file for the application.
You can also play template macros and QuickMacros from directly within WordPerfect. For
information, please see the Help file for WordPerfect.
This section contains the following procedures:
• To play a PerfectScript macro
Troubleshooting macro run-time errors
A run-time error is a problem that occurs while a macro is playing.
When a run-time error is encountered, an error message displays the location of the problem in the macro code.
For this reason, the best way to troubleshoot a run-time error is to consult its error message.
To play a PerfectScript macro
1 In the PerfectScript utility, click File ` Play.
2 Select the macro that you want to play, and then click Play.
You can also
Pause (or resume) a macro
Stop a macro
Every time a macro is played, it is recompiled and then saved. If you do not want to save over a macro
when you play it, you can create a new version of it by specifying a different path or filename in the
Play macro dialog box.
In Windows, you can access the commands for playing, pausing, and stopping a macro by rightclicking that macro.
You can specify the settings to use when playing macros. For information, see “To specify settings for
playing macros” on page 67.
In the PerfectScript utility, click
Pause
.
In the PerfectScript utility, click
.
Stop
File `
File `
76Playing PerfectScript macros
Making PerfectScript macros user-friendly
From directly within WordPerfect, Quattro Pro, or Presentations, you can assign a macro to a keystroke,
menu, toolbar, or property bar. For information, see the Help file for the application.
If you want to make a macro even more user-friendly, you can create a dialog box for it by using the Dialog
Editor feature of the PerfectScript utility. For information, see “Creating UI for PerfectScript macros” on
page 79.
Creating PerfectScript macros77
78Making PerfectScript macros user-friendly
Creating UI for PerfectScript macros
You can create dialog boxes for your PerfectScript macros if you want to provide an interface between the
application and the user (commonly called a “user interface,” or “UI”).
This section contains the following topics:
•“Understanding dialog boxes for PerfectScript macros” on page 79
• “Setting up dialog boxes for PerfectScript macros” on page 80
• “Setting up controls for PerfectScript dialog boxes” on page 84
• “Setting up callbacks for PerfectScript dialog boxes” on page 96
• “Testing PerfectScript dialog boxes” on page 101
• “Displaying PerfectScript dialog boxes” on page 101
Understanding dialog boxes for PerfectScript macros
Dialog boxes provide an interface between the application and the user.
Dialog boxes come in two types:
• modal — A modal dialog box locks the application until the user acts on that dialog box and closes it. The
File | Open dialog box in WordPerfect is an example of a modal dialog box because focus remains on this
dialog box until it is released.
• modeless — A modeless dialog box does not lock the application, so the user can move between the dialog
box and the application as necessary. The Find and Replace dialog box in WordPerfect is an example of a
modeless dialog box because you can continue working in a document while this dialog box is displayed.
Of the two dialog-box types, modal is the more common.
To use a modeless dialog box in your macro, you must enable the
InhibitInput property.
As a macro programmer, you can take advantage of dialog boxes in PerfectScript if you want to obtain
information or data from a user. Dialog boxes that are created in a macro can be used to ask questions or
otherwise gather data — data that, in turn, can be used to determine the flow and control of the macro.
You can create a dialog box in one of two ways:
• by writing PerfectScript code — The PerfectScript language provides programming commands for
manually coding dialog boxes.
• by using the PerfectScript Dialog Editor — The PerfectScript Dialog Editor provides a graphical
development environment for designing dialog boxes quickly and easily.
The Dialog Editor does not let you edit macros, only to define dialog boxes for them.
The Dialog Editor works only with macros that are in WordPerfect format. For this reason, you can
open the Dialog Editor either from within the PerfectScript utility or from within WordPerfect, as
explained in “To display the Dialog Editor” on page 66.
The first step in creating a dialog box is explained in “Setting up dialog boxes for PerfectScript macros” on
page 80.
Display property and disable the
Creating UI for PerfectScript macros79
The second step in creating a dialog box is explained in “Setting up controls for PerfectScript dialog boxes” on
page 84.
The third step in creating a dialog box is explained in “Setting up callbacks for PerfectScript dialog boxes” on
page 96.
The fourth step in creating a dialog box is explained in “Testing PerfectScript dialog boxes” on page 101.
The fifth and final step in creating a dialog box is explained in “Displaying PerfectScript dialog boxes” on
page 101.
Setting up dialog boxes for PerfectScript macros
You can set up a dialog box for a macro, either by writing PerfectScript code or by using the PerfectScript
Dialog Editor.
Setting up dialog boxes by using PerfectScript code
You can use the PerfectScript programming command DialogDefine to set up a dialog box.
The following code provides an example of a dialog box that is set up by using the
You can use + or | in parameters where multiple values can be specified. In the preceding example, the
syntax
Style parameter.
OK! | Percent! applies both the OK! enumeration and the Percent! enumeration to the
The following table describes the purpose of each parameter in the preceding example.
Parameter (or parameters)Description
Dialog
Left and TopWork together to specify the position of the top-left corner of the dialog box.
Specifies the name of the dialog box, which is used to refer to the dialog box
throughout the macro code. This name can consist of letters or numbers (or
both), and it must be unique.
In the preceding example, the name
box.
Dialog boxes are positioned in dialog-box units, whereby a vertical unit equals
1/8 the font height and a horizontal unit equals 1/4 the font width.
MainDialog is assigned to the dialog
In the preceding example, the
50 and are used with the Percent! enumeration of the Style parameter.
of
As a result, the dialog box is centered on the screen.
80Setting up dialog boxes for PerfectScript macros
Left and Top parameters are assigned a value
Parameter (or parameters)Description
Width and HeightWork together to determine the size of the dialog box. Dialog boxes are sized
in dialog-box units, whereby a vertical unit equals 1/8 the font height and a
horizontal unit equals 1/4 the font width.
Width and Height parameters are assigned
Style parameter is assigned the enumerations
"Example Dialog Box" is assigned to
Style
Caption
In the preceding example, the
values of
Specifies one or more dialog-box styles. These styles are used to determine the
appearance and function of the dialog box.
In the preceding example, the
OK! and Percent!. The OK! enumeration adds an OK button to the dialog
box. The
the percentage of the screen width or height minus the width or height of the
dialog box.
Specifies the text to be displayed in the caption (title) bar
In the preceding example, the text
the caption bar.
150 and 100 (respectively).
Percent! enumeration sets the Left and Top parameters to use
For more information about the DialogDefine command, please see the DialogDefine topic in the
PerfectScript Command Reference section of the Macro Help (psh.chm).
Setting up dialog boxes by using the Dialog Editor
You can use the Dialog Editor to add a dialog box to a macro. For information, see “To add a dialog box to a
PerfectScript macro by using the Dialog Editor” on page 81.
You can also use the Dialog Editor to set the properties for a dialog box. You can use properties to specify the
location and size of a dialog box, as well as its caption, Help file, Help key, type (modal or modeless), frame type,
and attributes. For more information, see “To set the properties for a dialog box by using the Dialog Editor” on
page 83.
You can use the Dialog Editor to choose the typeface and point size for the text in a dialog box. Changes in font
size and style affect the size of the dialog box. For more information, see “To set the font for a dialog box by
using the Dialog Editor” on page 83.
Finally, you can use the Dialog Editor to save a dialog box in the current macro. For information, see “To save
a dialog box in the current macro by using the Dialog Editor” on page 84.
To add a dialog box to a PerfectScript macro by using the Dialog Editor
1 In the PerfectScript utility, click To o l s `Dialog Editor.
The Edit Macro Dialogs dialog box appears.
2 Select the desired macro, and then click OK.
The Dialog Editor for that macro appears.
3 Click File ` New, and then type a name for the new dialog box.
4 Set the properties for the dialog box. For information, see “To set the properties for a dialog box by using
the Dialog Editor” on page 83.
5 Select the dialog box, and then click File`Open.
Creating UI for PerfectScript macros81
The dialog box is opened for editing in the Dialog Editor.
6 Do any of the following:
• Set the font for the dialog box. For information, see “To set the font for a dialog box by using the Dialog
Editor” on page 83.
• Add controls to the dialog box. For information, see “Setting up controls for PerfectScript dialog boxes”
on page 84.
7 Click File ` Save, and then click File ` Close. For more information, see “To save a dialog box in the
current macro by using the Dialog Editor” on page 84.
8 Test the dialog box. For information, see “Testing PerfectScript dialog boxes” on page 101.
9 Write macro code for opening and closing the dialog box. For information, see “Displaying PerfectScript
dialog boxes” on page 101.
Dialog-box names are case-sensitive. Be sure to correctly reference them in your macros.
When you save a dialog box, its size and position are recorded. When you open a saved dialog box, its
size and position are loaded, applied, and maintained during the current session of PerfectScript.
You can also
Copy a dialog box by using the Dialog Editor
Edit a dialog box by using the Dialog Editor
Rename a dialog box by using the Dialog Editor
In the PerfectScript utility, click Tools
macro that contains the dialog box, and then click OK. Click Edit
Copy. Open the macro file to which you want to copy the dialog
`
box, and then click Edit
desired.
In the PerfectScript utility, click Tools
macro that contains the dialog box, and then click OK. Doubleclick the dialog box that you want to edit, and then edit the dialog
box as desired. Click Edit
the current macro file.
In the PerfectScript utility, click Tools
macro that contains the dialog box, and then click OK. Select the
dialog box, and then click File
the dialog box.
NOTES:
• Dialog-box names are case-sensitive. Be sure to correctly reference
them in your macros.
• Renaming a dialog box gives it a new name in the current macro
file, but it does not change the name that is displayed on the
caption bar.
• Remember to update the macro code with new name of the dialog
box.
`Paste. Rename the pasted dialog box, if
`Save to save the edited dialog box in
`Dialog Editor. Select the
`Dialog Editor. Select the
`Dialog Editor. Select the
`Rename. Type a new name for
82Setting up dialog boxes for PerfectScript macros
You can also
Delete a dialog box by using the Dialog Editor
In the PerfectScript utility, click Tools
macro that contains the dialog box, and then click OK. Select the
dialog box, and then click File
you want to delete the dialog box.
NOTE: Remember to remove all references to the deleted dialog
box from the macro code.
`Dialog Editor. Select the
`Delete. Click Ye s to confirm that
To set the properties for a dialog box by using the Dialog Editor
1 In the PerfectScript utility, click To o l s ` Dialog Editor.
2 Select the macro that contains the dialog box, and then click OK.
3 Select the dialog box, and then click File ` Properties.
4 In the Dialog Properties dialog box that appears, specify any of the following properties for the dialog
box:
• location and size
• caption
• Help file
• Help key
• dialog-box type
• frame type
• attributes
You can choose between two dialog-box types: modal and modeless. A modal dialog box locks the
macro until the user acts on that dialog box and closes it. A modeless dialog box does not lock the
macro, so the user can move between the dialog box and the macro as necessary.
To set the font for a dialog box by using the Dialog Editor
1 In the PerfectScript utility, click To o l s ` Dialog Editor.
2 Select the macro that contains the dialog box, and then click OK.
3 Select the dialog box, and then click File ` Open.
4 Click Dialog ` Font.
5 In the Dialog Font dialog box that appears, specify any of the following font attributes:
• style
• size
The font size that you choose affects the size of the dialog box — the larger the font, the larger the
dialog box.
The caption font remains constant for all dialog boxes.
Creating UI for PerfectScript macros83
To save a dialog box in the current macro by using the Dialog Editor
1 With the dialog box open for editing in the Dialog Editor, click File `Save to save the dialog box in the
current macro file.
2 Click File`Close to stop editing the dialog box and close its Dialog Editor.
Setting up controls for PerfectScript dialog boxes
You can set up controls for a dialog box, either by writing PerfectScript code or by using the PerfectScript
Dialog Editor. Controls are input or output windows where the user interacts with a dialog box and its parent
application. You can use any of the following control types in your dialog boxes:
• bitmap — see “Bitmap controls” on page 85
• button — see “Button controls” on page 86
• check box — see “Check box controls” on page 86
• color wheel — see “Color wheel controls” on page 87
• combo box — see “Combination (“combo”) box controls” on page 87
• counter — see “Counter controls” on page 87
• custom control — see “Custom controls” on page 88
• date control — see “Date controls” on page 88
• edit box — see “Edit box controls” on page 88
• filename box — see “Filename box controls” on page 89
• frame — see “Frame controls” on page 89
• group box — see “Group box controls” on page 89
• line — see “Line controls” on page 90
• list control — see “List controls” on page 90
• progress indicator — see “Progress indicator controls” on page 91
• scroll bar — see “Scroll bar controls” on page 91
• static text — see “Static text controls” on page 91
• viewer — see “Viewer controls” on page 91
You can add controls to a dialog box by writing macro code. The PerfectScript language provides a
programming command for creating each control type — simply insert these commands after the
DialogDefine command (see “Setting up dialog boxes by using PerfectScript code” on page 80) for the dialog
box.
In the following example, the PerfectScript programming command
text control (named
84Setting up controls for PerfectScript dialog boxes
Control2) to the dialog box named MainDialog by using the specified parameters:
VScroll! | Multiline!; vReturn; 1000)
For information about the PerfectScript programming commands for creating dialog-box controls,
please see the PerfectScript Command Reference section of the Macro Help (psh.chm).
Alternatively, you can use the Dialog Editor to set up controls in any of the following ways:
• by adding controls to a dialog box. For information, see “To add a control to a PerfectScript dialog box by
using the Dialog Editor” on page 92.
• by setting the properties for the controls in a dialog box. The properties that are available to a control
depend on the control type. For information, see “To set the properties for a control by using the Dialog
Editor” on page 93.
• by positioning the controls in a dialog box, either at specified locations or in relation to each other. For
information, see “To position one or more controls by using the Dialog Editor” on page 94.
• by assigning behaviors to the controls in a dialog box. For information, see “To assign behaviors to one or
more controls by using the Dialog Editor” on page 95.
Some controls require the use of a hot spot — an invisible control that closes the dialog box when the
user clicks the defined area. (The response for a hot spot can be redefined with a callback function.) The
PerfectScript command for creating a hot spot is
DialogAddHotSpot. For information about this
command, please see the PerfectScript Command Reference section of the Macro Help (psh.chm).
The PerfectScript language lets you create one type of control that is not supported by the Dialog
Editor: an icon control, which is represented by the programming command
DialogAddIcon. An icon
control does not accept input, unless it is used in a callback function with the PerfectScript command
DialogAddHotSpot. For information about these commands, please see the PerfectScript Command
Reference section of the Macro Help (psh.chm).
Variables that are associated with controls work the same way with dialog boxes that are created by
using PerfectScript code as they do with dialog boxes that are created by using the Dialog Editor. If a
variable exists, its value is set into the controls when the dialog box is opened, and the value in the
controls is set into the variables when the dialog box is closed. For more information about using
PerfectScript code to open and close dialog boxes, see “Displaying PerfectScript dialog boxes” on
page 101.
Bitmap controls
You can display a bitmap as a control. By default, the bitmap appears without a border on the background of
the dialog box; however, for visual clarity, you can give the bitmap an outline. A bitmap control looks like this:
The PerfectScript command for creating a bitmap control is DialogAddBitmap. For information about
this command, please see the DialogAddBitmap topic in the PerfectScript Command Reference section
of the Macro Help (psh.chm).
A bitmap control does not accept input, unless it is used in a callback function with the PerfectScript
command
DialogAddHotSpot. For information about this command, please see the
DialogAddHotSpot topic in the PerfectScript Command Reference section of the Macro Help
(psh.chm).
Creating UI for PerfectScript macros85
Button controls
You can add three kinds of buttons to a dialog box: pop-up buttons, push buttons, and radio buttons.
A pop-up button displays a list of options when clicked. The button itself shows the selected option.
A pop-up button looks like this when it is closed:
A pop-up button looks like this when it is clicked:
A push button activates a specific action — such as OK, Cancel, or Help — when clicked. A push button looks
like this:
Radio buttons are used in groups to represent options that are mutually exclusive. Enabling one radio button
disables another. A radio button looks like this:
The PerfectScript command for creating a push-button control is
command for creating a radio-button control is
DialogAddRadioButton. For information about these
DialogAddPushButton, and the
commands, please see the DialogAddPushButton and DialogAddRadioButton topics in the
PerfectScript Command Reference section of the Macro Help (psh.chm).
A radio-button control uses a callback function to activate user-defined responses.
Check box controls
Check boxes are used in groups to represent options that are compatible. Clicking an empty check box enables
that option, while clicking a marked check box disables that option. A check box looks like this:
The PerfectScript command for creating a check-box control is
DialogAddCheckBox. For information
about this command, please see the DialogAddCheckBox topic in the PerfectScript Command
Reference section of the Macro Help (psh.chm).
A check-box control uses a callback function to activate user-defined responses.
You can define a check box as “Three State” if you want it to provide a state of unavailability (that is,
a state in which the box is checked and grayed) in addition to an enabled state and a disabled state.
86Setting up controls for PerfectScript dialog boxes
Color wheel controls
A color wheel lets the user select a color based on values of hue, lightness, and saturation. A color wheel looks
like this:
The PerfectScript command for creating a color-wheel control is
DialogAddColorWheel. For
information about this command, please see the DialogAddColorWheel topic in the PerfectScript
Command Reference section of the Macro Help (psh.chm).
In a color-wheel control, you can use the arrow keys to move the color selection. Hold down Ctrl while
using the arrow keys to change the value of the color-saturation bar.
Combination (“combo”) box controls
A combo box combines an edit box (see “Edit box controls” on page 88) with a list box (see “List controls” on
page 90). You can enter text in the edit box, or you can double-click a list item to insert it.
A combo box looks like this when it is closed:
A combo box looks like this when it is clicked:
The PerfectScript command for creating a combo-box control is
DialogAddComboBox. For
information about this command, please see the DialogAddComboBox topic in the PerfectScript
Command Reference section of the Macro Help (psh.chm).
Counter controls
A counter lets the user enter numeric data in an edit box (see “Edit box controls” on page 88), either by typing
in the edit box or by clicking the built-in incrementor/decrementor control. A counter looks like this:
The PerfectScript command for creating a counter control is
DialogAddCounter. For information
about this command, please see the DialogAddCounter topic in the PerfectScript Command Reference
section of the Macro Help (psh.chm).
Creating UI for PerfectScript macros87
Custom controls
A custom control lets you, the macro programmer, create a control by specifying its settings for text, class, and
attributes. A custom control looks like this:
The PerfectScript command for creating a custom control is
DialogAddControl. For information
about this command, please see the DialogAddControl topic in the PerfectScript Command Reference
section of the Macro Help (psh.chm).
Date controls
A date control displays an edit box (see “Edit box controls” on page 88) and a calendar icon. The user can enter
a date by typing in the edit box or by clicking the calendar icon and choosing a date from the calendar that
appears. A date control looks like this when the calendar icon is clicked:
The PerfectScript command for creating a date control is
DialogAddDate. For information about this
command, please see the DialogAddDate topic in the PerfectScript Command Reference section of the
Macro Help (psh.chm).
In a date control, you can use the following keyboard shortcuts to change the date more quickly:
•holding Ctrl while clicking an arrow icon — increases the tens column
•holding Alt while clicking an arrow icon — increases the hundreds column
•pressing Alt + arrow key — changes the month by one month
•pressing Page Up or Page Down — changes the year
•pressing Alt — changes the year by one year
•pressing Alt + Ctrl — changes the year by 10 years
•pressing Alt + Shift — changes the year by 100 years
Edit box controls
An edit box lets the user type text, or it lets the macro type text on the user’s behalf. An edit box can have one
or more lines. An edit box looks like this:
88Setting up controls for PerfectScript dialog boxes
The PerfectScript command for creating an edit-box control is DialogAddEditBox. For information
about this command, please see the DialogAddEditBox topic in the PerfectScript Command Reference
section of the Macro Help (psh.chm).
Filename box controls
A filename box displays an edit box (see “Edit box controls” on page 88) and a folder button. The user can
specify a file either by typing the filename (and its path) or by clicking the folder button to display a Browse
dialog box. A filename box looks like this:
The PerfectScript command for creating a filename-box control is
DialogAddFileNameBox. For
information about this command, please see the DialogAddFileNameBox topic in the PerfectScript
Command Reference section of the Macro Help (psh.chm).
Frame controls
A frame can be used to visually group the items in a dialog box, or to act as a design element. A frame looks
like this:
The PerfectScript command for creating a frame control is
DialogAddFrame. For information about
this command, please see the DialogAddFrame topic in the PerfectScript Command Reference section
of the Macro Help (psh.chm).
A frame control does not accept input.
Group box controls
A group box visually groups controls by using a titled frame. A group box looks like this:
The PerfectScript command for creating a group box control is
DialogAddGroupBox. For information
about this command, please see the DialogAddGroupBox topic in the PerfectScript Command
Reference section of the Macro Help (psh.chm).
A group box control does not accept input.
Creating UI for PerfectScript macros89
A group box can group controls visually, but not functionally. To make the controls in a group box
function as a group, you can use the Control Order and Control Groups features in the Dialog Editor,
as explained in “To assign behaviors to one or more controls by using the Dialog Editor” on page 95.
Line controls
You can use a horizontal line or a vertical line to visually separate the items in a dialog box.
A horizontal line looks like this:
A vertical line looks like this:
The PerfectScript command for creating a horizontal line control is
command for creating a vertical line control is
DialogAddVLine. For information about these
DialogAddHLine, while the
commands, please see the DialogAddHLine and DialogAddVLine topics in the PerfectScript
Command Reference section of the Macro Help (psh.chm).
A line control does not accept input.
List controls
A list control displays a series of options (or “list items”) from which to choose. A list control takes one of the
following forms:
• a pop-up list — presents the list items in a pop-up window
• a drop-down list — presents the list items in a window that extends outward from the list control
• a list box — presents the list items in a window that acts much like a viewer (see “Viewer controls” on
page 91)
A list box looks like this:
The PerfectScript command for creating a list box control is
for creating a list item is
DialogAddListItem. For information about these commands, please see the
DialogAddListBox, while the command
DialogAddListBox and DialogAddListItem topics in the PerfectScript Command Reference section of
the Macro Help (psh.chm).
90Setting up controls for PerfectScript dialog boxes
Progress indicator controls
A progress indicator displays the progress of a process as it runs. A progress indicator looks like this:
The PerfectScript command for creating a progress indicator control is
DialogAddProgress. For
information about this command, please see the DialogAddProgress topic in the PerfectScript
Command Reference section of the Macro Help (psh.chm).
Scroll bar controls
A scroll bar lets the user scroll the viewable area. A horizontal scroll bar moves the viewable area left and right,
while a vertical scroll bar moves the viewable area up and down.
A horizontal scroll bar looks like this:
A vertical scroll bar looks like this:
The PerfectScript command for creating a scroll bar control is
DialogAddScrollBar. For information
about this command, please see the DialogAddScrollBar topic in the PerfectScript Command Reference
section of the Macro Help (psh.chm).
A scroll bar control can use a callback function to activate user-defined responses.
Static text controls
Static text provides the user with one or more lines of read-only information, such as instructions. Static text
looks like this:
The PerfectScript command for creating a static text control is
DialogAddText. For information about
this command, please see the DialogAddText topic in the PerfectScript Command Reference section of
the Macro Help (psh.chm).
A static text control does not accept input.
You can copy static text from most dialog boxes that are part of a macro system. However, you cannot
copy static text from user-defined dialog boxes.
Viewer controls
A viewer displays a read-only, scrollable text file. A viewer looks like this:
Creating UI for PerfectScript macros91
The PerfectScript command for creating a viewer control is DialogAddViewer. For information about
this command, please see the DialogAddViewer topic in the PerfectScript Command Reference section
of the Macro Help (psh.chm).
To add a control to a PerfectScript dialog box by using the Dialog Editor
1 In the PerfectScript utility, click To o l s ` Dialog Editor.
2 Select the macro that contains the dialog box, and then click OK.
The Dialog Editor for that macro appears.
3 Select the dialog box, and then click File`Open.
The dialog box is opened for editing in the Dialog Editor.
4 Add the desired type of control by clicking its corresponding command on the Control menu (or by
clicking its corresponding toolbar icon):
• bitmap — Control ` Bitmap
• button, push — Control ` Buttons ` Push
• button, radio — Control ` Buttons ` Radio
• check box — Control ` Check Box
• color wheel — Control ` Color Wheel
• combo box — Control ` Combo Box
• counter — Control`Counter
• custom control — Control ` Custom
• date control — Control ` Date
• edit box — Control`Edit Box
• filename box — Control ` Filename Box
• frame — Control ` Fr
• group box — Control ` Group Box
• line, horizontal — Control ` Lines ` Horizontal
• line, vertical — Control`Lines`Ver ti cal
• list control — Control ` List Box
• progress indicator — Control ` Progress Indicator
• scroll bar, horizontal — Control ` Scroll Bars ` Horizontal
• scroll bar, vertical — Control ` Scroll Bars `Ver ti cal
• static text — Control `Static Text
• viewer — Control ` Viewer
ame
5 Position the pointer where you want the top-left corner of the control to appear, and then click.
You can also
Select a control in the Dialog EditorClick the control.
Select multiple controls in the Dialog EditorHold down Shift, and click the controls. The last control that you click
is called the “anchor control,” and it appears with black squares around
it
92Setting up controls for PerfectScript dialog boxes
You can also
Move a control in the Dialog EditorDrag the control.
TIP: For information about precisely positioning a control, see “To
position one or more controls by using the Dialog Editor” on page 94.
Resize a control in the Dialog EditorDrag one of the handles for the control.
Copy a control in the Dialog EditorRight-click the control, and then click Copy. Drag the copy to position
it.
NOTE: The copy has all the properties of the original control, but you
can change them if desired.
TIP: You can also copy a control by holding down Ctrl while selecting
it.
Edit a control in the Dialog EditorDouble-click the control, and then set its properties. For information,
see “To set the properties for a control by using the Dialog Editor” on
page 93.
Delete a control in the Dialog EditorDo one of the following:
• Right-click the control, and then click Delete.
• Select the control, and then press Delete.
To set the properties for a control by using the Dialog Editor
1 With the dialog box open for editing in the Dialog Editor, display the properties for the control by doing
one of the following:
• Double-click the control.
• Right-click the control, and then click Properties.
The Properties dialog box for the control appears.
2 Set the properties for the control. The properties that are available to a control depend on the control type,
as follows:
• bitmap — location and size; named region; variable; filename; attributes
• button, push — location and size; named region; text; type
• button, radio — location and size; named region; variable; text; type; text placement; initial state
• check box — location and size; named region; variable; text; type; text placement; initial state
• color wheel — location and size; named region; variable; initial color values
• combo box — location and size; named region; variable; style; current item list; type; attributes
• counter — location and size; named region; variable; values; attributes
• custom control — location and size; named region; text; class; styles
• date control — location and size; named region; variable; initial date; attributes
• edit box — location and size; named region; variable; style; text; type; justification; capitalization;
attributes; automatic scroll; scroll bar
• filename box — location and size; named region; variable; folder; template; type
• frame — location and size; named region; type; color
• group box — location and size; named region; text
Creating UI for PerfectScript macros93
• line, horizontal — location and size; named region
• line, vertical — location and size; named region
• list control — location and size; named region; variable; style; current item list; attributes
• progress indicator — location and size; named region
• scroll bar, horizontal — location and size; named region; variable; values; alignment and sizing
• scroll bar, vertical — location and size; named region; variable; values; alignment and sizing
• static text — location and size; named region; variable; style; text; justification; prefix; type
• viewer — location and size; named region; variable; filename
A control name is specified by the Named region property. Control names are case-sensitive, so be
sure to correctly reference them in your macros.
You can use the Properties dialog box to determine a precise location and a precise size for a control.
However, you can roughly position a control by dragging it around the dialog box, and you can roughly
size it by dragging one of its handles. For more information about positioning controls, see “To position
one or more controls by using the Dialog Editor” on page 94.
You can also
Create or edit the item list for a combo box
or a list control
In the Properties dialog box for the control, click Create/Edit List,
and then do any of the following:
• add an item — Type the name of the item in the List item box, and
then click Add. The item is added to the list, in the List box.
• select an item in the List box— Click the item.
• edit an item — Select the item, type a new value in the List item box,
and then click Replace.
• move an item up the list — Select the item, and then click Move Up
until the item reaches the desired position.
• move an item down the list — Select the item, and then click Move Down until the item reaches the desired position.
• set the default list item — Select the item, and then click Set Initial.
The item appears in the Initial line.
• delete an item — Select the item, and then click Delete.
• sort the list alphabetically — Enable the Sort List check box. NOTE:
Enabling this check box prevents you from manually rearranging the
list items.
To position one or more controls by using the Dialog Editor
• With the dialog box open for editing in the Dialog Editor, position one or more controls by using any of the
methods in the following table.
ToDo the following
Position a single control roughlyDrag the control to the desired position in the dialog box.
TIP: You can roughly size the control by dragging one of its handles.
94Setting up controls for PerfectScript dialog boxes
ToDo the following
Position a single control preciselyDouble-click the control to open its Properties dialog box. In the
Location and size area, determine the position of the top-left corner of the control by specifying values in the Left and To p boxes.
TIP: You can precisely size the control by specifying values in the
Width and Height boxes.
Position multiple controls roughlySelect the controls, and then drag them to the desired position in the
dialog box.
Position multiple controls in relation to each
other
You can also
Use a grid to position controls
Select the controls, and then position them in any of the following
ways:
• aligned with one side of the anchor control — Click Align, and then
click Left, Right, To p , or Bottom.
• centered in relation to the anchor control — click Align
and then click Ve rt ical or Horizontal.
• spaced in relation to each other — click Align
then click Ver ti ca l or Horizontal.
TIP: You can make the selected controls the same size as the anchor
control by clicking AlignHeight, Width, or Both.
Display the grid by clicking View
Snap to Grid to force controls to align with the points on that grid.
TIP: If you want to specify the amount of space between grid points
on each axis, click View
`Make Same Size and then clicking
`Show Grid, and click View`
`Grid Options.
`Space Evenly, and
`Center,
To assign behaviors to one or more controls by using the Dialog Editor
• With the dialog box open for editing in the Dialog Editor, assign behaviors to one or more controls by
using any of the methods in the following table.
ToDo the following
Specify the control that has focus when the
dialog box opens
Define related controls as a group
Creating UI for PerfectScript macros95
Click Dialog
control. Click OK in the Initial Focus dialog box to apply your
changes.
Click Dialog
controls. Click OK in the Control Groups dialog box to apply your
changes.
NOTE: To create a functioning group of controls, you must set their
order. You must also draw a group box around them (see “Group box
controls” on page 89).
`Initial Focus. In your dialog box, click the desired
`Control Groups. In your dialog box, click the desired
ToDo the following
Specify the controls that you want the user
to be able to tab through
Specify the default button for a control,
which is activated when the user presses
Enter on that control
Click Dialog
controls. Click OK in the Tab Sto ps dialog box to apply your changes,
and then click Dialog
controls in the desired order. Click OK in the Control Order dialog
box to apply your changes.
Click Dialog
control, and then click the button that you want as the default for that
control. Click OK in the Default Button dialog box to apply your
changes.
`Ta b S t op s. In your dialog box, click the desired
`Control Order. In your dialog box, click the
`Default Button. In your dialog box, click the desired
Setting up callbacks for PerfectScript dialog boxes
As previously discussed (see “Understanding PerfectScript callbacks” on page 58), you can create callbacks for
dialog boxes. Using a dialog-box callback lets the macro gather information from an active dialog box, rather
than waiting until the dialog box is closed to gather that information. For example, you can use a dialog-box
callback to return the value of a control without having to close the dialog box, or to refresh the contents of a
control without having to destroy and reopen the dialog box.
Creating dialog-box callbacks
There are two requirements for creating a dialog-box callback.
The first requirement for creating a callback is to specify the name of the label to which to send callback
messages. This label name is specified in the third parameter of the
for certain events, you must create statements for those events inside this label. At the end of the routine, a
mandatory Return command ensures that the callback loop functions properly.
DialogShow command. If you need to watch
The name in the label parameter of the
DialogShow command may refer to either a label or a
procedure. This parameter creates an implicit array of eleven elements, which has the same name as
that label or procedure. The messages that are sent to the callback are accessed through these array
elements.
The actual
Label...Return structure can be placed anywhere in your macro. It is better, however, to
create a section in your macro just for labels, functions, and procedures.
The second requirement for creating a callback is to create a callback-message loop, which is necessary for
trapping dialog-box events. The loop holds control of the macro until the loop is terminated. You can create a
callback-message loop either by using the
CallBackWait command or by using a While loop.
The following code segment shows a skeleton callback function:
DialogShow(1000; "WordPerfect"; Msgs)
CallbackWait
// This command initializes the loop.
Quit
Label(Msgs)
// This label identifies where dialog box events are watched.
96Setting up callbacks for PerfectScript dialog boxes
Loading...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.