Decisions |
13.1
The If() command is the method by which a macro
makes a decision. If the condition tested is true, the commands
governed by the If() command are executed,
otherwise they are not.
The basic form of the If() command is:
|
|||||||||||||||||||||||||||||||||||||||||||
| If (condition) | |
| EndIf |
Note that the condition is placed in parentheses, like a parameter, and that there is no space in EndIf.
If the condition is true, the commands between If() and EndIf will be executed. If the condition is not true, these commands will be skipped. In either case, macro execution continues with the command following the ENDIF statement.
Examples:
| If (x=0) | // if variable x has a value of 0 | |
| EndIf |
| If (?Page=5) | // if cursor is on page 5 | |
|
| ||
| EndIf | ||
Indentation is not strictly necessary, but it makes the macro
easier to read. As mentioned earlier, tabs, indents and extra
spaces and other formatting of the macro document are ignored by
the macro compiler; they only affect the visual presentation of
the macro when you edit it.
The Else statement| If (condition) | |
| Else | |
| EndIf |
Example:
| If (?SelectedText="THE END") | |
| Else | |
| EndIf |
As shown in the above example, sometimes when a certain condition exists you will want to have the macro end. To do so, use the Quit() command.
Multiple conditions are permitted in an IF() statement. The Switch() command offers an efficient substitute for multiple IF() commands. These topics are beyond the scope of this tutorial.
© 1999 Seth H. Katz
All rights reserved
E-MAIL TO AUTHOR
![]() |
![]() |
![]() |