|
Macro Command Help |
Macro Command Name |
Menu Path |
Link to Command Table |
IF |
Access via macro or menu only |
Introduction
Evaluates one or more logical expressions involving substitution variables and constants in a macro or menu.
How to use
There are two categories of IF command, namely:
-
SIMPLE
-
BLOCKED
Simple IF command
General Format:
!IF <CONDITION>, ... ,GOTO XXXX
!IF <CONDITION>, ... ,GOSUB XXXX
!IF <CONDITION>, ... ,LET <EXPR>
A series of comma separated conditions may be supplied. If all conditions evaluate to "true", an attached GOTO, GOSUB or LET statement is executed.
<CONDITION> can be one of either : <VAR1> <OP> <VAR2> or : <LVAR>
Where: |
<VAR1> |
is a substitution variable |
|
|
|
|
<VAR2> |
is a substitution variable or a constant. |
|
|
|
|
<OP> |
is one of the following operators
< Less than <= Less than or equal to = Equal to >= Greater than or equal to > Greater than <> Not equal to". |
|
|
|
|
<LVAR> |
is a "logical" variable. The expression is "false" if <LVAR> = 0 or 0.0, and "true" for all other values. Note : All alphanumeric values evaluate as "true" |
|
|
|
XXXX |
is a 16 character label in the macro or menu.
|
<EXPR> |
is any valid expression recognized by the LET command. |
If <VAR1> and <VAR2> are numeric they are compared as numbers. Otherwise they are compared character by character using the collating sequence. Variables and values may be enclosed in single quotes ' to preserve spaces.
Substitution variables must be defined for comparison, a macro error results if comparison is attempted on undefined variables.
Blocked IF command
General Format:
!IF <CONDITION>, ... ,THEN
statement(s)
!ELSEIF <CONDITION>, ...,THEN
statement(s)
!ELSEIF <CONDITION>, ...,THEN
statement(s)
!ELSE
statement(s)
!ENDIF
The "blocked" IF statement is an extension of the simple IF statement. Each <CONDITION> line is evaluated in turn. The block of statements associated with the FIRST <CONDITION> line to evaluate "true" is executed. Once this block is finished, control passes to the first statement after the !ENDIF.
<CONDITION>s are specified in the same way as for "simple" IF statements.
Zero or more !ELSEIF ...,THEN branches may be supplied.
An optional !ELSE branch may be supplied. This is executed only when all preceding branches fail.
!ENDIF MUST be supplied to terminate the "block".
IF blocks may be nested.
It is legal to GOSUB from within a branch. The branch will be "pending", and control will resume with the !RETURN.
It is illegal to GOSUB or GOTO a label contained within an IF statement block either from outside the whole IF block, or to a label within a different or deeper branch of the whole block.
Notes
Because testing is abandoned if any individual test fails, then syntax errors further to the right in the line (such as an illegal label) will not be picked up unless all tests pass.
During character tests, blanks will be stripped out from the <val1> string unless it is enclosed in quotes. This is true even if <val1> is a second substitution variable. If in doubt, enclose <val1> in quotes.
Example
1. |
GOTO the label "END" if variable $1 contains the numeric value '3' (e.g. 3, 3.0 etc) AND if variable $2 is NOT set to the string "Xyz Project". Capitals are significant for string comparison. !IF $1 = 3, $2 <> 'Xyz Project', GOTO END
|
2. |
Check the variable "$value#" and initialize it to the string "New Value" if it has not already been defined. Note the use of single quotes. !LET $test#=$value# !IF $test#='$value' '#', LET $value#='New Value'
|
3. |
This example will delete file DRILL.M if it exists. A message is also displayed. !FILE $exists#=DRILL.M,$recs#=recs !IF $exists#, THEN !DELETE &IN(DRILL.M) !ECHO file DRILL.M deleted. !ENDIF
|
4. |
Classify a plot as either A4, A3 or A0 depending on the plot dimensions $min#, $max#. Indentation may be used to make the branching clearer. !IF $min#>0, $min#<=210, $max#<=297, THEN !LET $media#='A4' !ELSEIF $min#<=297, $max#<=420, THEN !LET $media#='A3' !ELSEIF $min#<=841, $max#<=1189, THEN !LET $media#='A0' !ELSE !LET $media#='Plot size error.' !ENDIF
|
Error and Warning Messages
>>> |
!IF: TEST ON NON_EXISITENT SUBSTITUTION VARIABLE OR FLAG <<< <listing of command line> |
>>> |
ERR 80 <<<( 0) IN SOFTIF |
|
The substitution variable was not defined, or the flag was not one of the set @FLAG1-5. Fatal; the macro or menu is abandoned. |
|
|
>>> |
!IF: SUBSTITUTION VARIABLE BLANK OR >8 CHARACTERS <<< <listing of command line> |
>>> |
ERR 88 <<<( 0) IN SOFTIF |
|
Illegal format for substitution variable. Fatal; the macro or menu is abandoned. |
|
|
>>> |
!IF: NO GOTOXXXX COMMAND <<< <Listing of command line> |
>>> |
ERR 74 <<<( 0) IN SOFTIF |
|
No GOTO command was found. Fatal; the macro or meny is abandoned. |
|
|
>>> |
INCORRECT LABEL XXXX IN GOTOXXXX OR XXXX NOT FOUND <<< <listing of command line> |
>>> |
ERR 75 <<<( recordno) IN MACGET |
|
Either the label (displayed below the message) was too long (>4 Characters) or was not found in the menu or macro. Fatal; the menu or macro is abandoned. Recordno is the record number in the menu or macro (from !START). |