The following snippets of macro code show how some macro functions are implemented. If you attempt to duplicate them in your own macros, ignore the line numbers (they exist for reference purposes only).
Syntax: ASKBOX
<title>
<message text>
…
<message text>
<blank line>
Use the ASKBOX macro command to receive yes/no feedback from the user. IFERR is set if the user clicks on No, and cleared if they click on Yes.
The following macro asks the user if the current color should be set to red (color #2). If the user answers Yes, the macro processes line 09. If the user answers No, the IFERR flag is set, so the macro jumps to line 10, which essentially ends the macro.
Note that line 03 defines the title of your message box. The following lines (05 & 06) define the text. Line 07 is intentionally blank, as it marks the end of the message box text.
01 macro CC
02 ASKBOX
03 Change Color
04 Would you like to
05 change the color
06 to red?
07
08 IFERR fin
09 color;2
10 :fin
11 endm
Syntax: IFDEF <variable> <label>
IFDEF checks to see if the specified variable has been defined. If it has, then the macro jumps to the specified goto label. If not, then the macro can then initialize variables. This is useful for ensuring that variables used later in the macro do indeed exist (an undefined variable in an IFx command causes a macro to get out of sync and fail).
The following macro is called by another macro. Line 02 contains the IFDEF command. If the variable WS has already been defined, the macro jumps to line 04 (the "Ok" label) and finishes. However, it the variable WS has not yet been defined, then it is created and initialized in line 03.
01 macro RESET
02 IFDEF WS Ok
03 GV WS 0
04 :Ok
05 endm
Syntax: SELREST
Please see SELSAVE for usage notes.
Syntax: SELSAVE
The SELSAVE and SELREST commands are used together to save and restore the Select by modes, respectively. Without these commands, changed selection modes persist even after the macro has exited. To preserve the pre-macro SELBY mode, start your macros with SELSAVE, and finish them with SELREST.
The following macro simply draws a line from point (1,1) to point (3,3). But then it uses the SELBYP command to change the selection mode to Prior. Then it changes the color of line to blue (color #3), and the layer of the line to "Merge". The selsave and selrest commands assure that after the macro finishes, the original SELBY mode (usually Dialog or Popup) is restored. Otherwise, the next editing command would automatically select the valid Prior entity.
01 macro LL3
02 selsave
03 line 1,1 3,3;
04 selbyp
05 changec 3
06 changel Merge
07 selrest
08 endm