IF…THEN
Description
A control structure used to cause a script to perform a specified
action if a stated condition is true. Syntax
1 uses a single-line format, and Syntax 2 uses a multiline format.
Syntax
Syntax 1 (the single-line format):
|
1 |
IF <span>condition</span> THEN <span>action1</span> {ELSE <span>action2</span>} |
|
Parameter |
Description |
|---|---|
|
condition |
The condition you want to test. |
|
action1 |
The action you want performed if the |
|
action2 |
The action you want performed if the |
Syntax 2 (the multiline format):
|
1 |
IF <span>condition1</span> THEN<span><br> action1<br></span>{ ELSEIF <span>condition2</span> THEN<br><span> action2</span> <br>. . . }<br>{ ELSE<span><br> action3 </span>}<br>END IF |
|
Parameter |
Description |
|---|---|
|
condition1 |
The first condition you want to test. |
|
action1 |
The action you want performed if condition1 is true. |
|
condition2 |
The condition you want to test if condition1 is false. |
|
action2 |
The action you want performed if condition2 is true. |
|
action3 |
The action you want performed if none |
Usage
You can use continuation characters to place the single-line
format on more than one physical line in the script.
You must end a multiline IF…THEN control
structure with END IF (which is two words).
Examples
This single-line IF…THEN statement opens
window w_first if Num is
equal to 1; otherwise, w_rest is opened:
|
1 |
IF Num = 1 THEN Open(w_first) ELSE Open(w_rest) |
This single-line IF…THEN statement displays
a message if the value in the SingleLineEdit sle_State is “TX”.
It uses the continuation character to continue the single-line statement
across two physical lines in the script:
|
1 |
IF sle_State.text="TX" THEN &<br>   MessageBox("Hello","Tex") |
This multiline IF…THEN compares the horizontal
positions of windows w_first and w_second.
If w_first is to the right of w_second, w_first is moved
to the left side of the screen:
|
1 |
IF w_first.X > w_second.X THEN<br>   w_first.X = 0<br>END IF |
This multiline IF…THEN causes the application
to:
-
Beep twice if X equals
Y -
Display the Parts list box and highlight item 5
if X equals Z -
Display the Choose list box if X is blank
-
Hide the Empty button and display the Full button
if none of the above conditions is true1IF X=Y THEN<br>   Beep(2)<br>ELSEIF X=Z THEN<br>   Show (lb_parts); lb_parts.SetState(5,TRUE)<br>ELSEIF X=" " THEN<br>   Show (lb_choose)<br>ELSE<br>   Hide(cb_empty)<br>   Show(cb_full)<br>END IF