6 Understanding PerfectScript macro concepts
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: