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 condition THEN action1 {ELSE action2} |
|
Parameter |
Description |
|---|---|
|
condition |
The condition you want to test. |
|
action1 |
The action you want performed if the condition is |
|
action2 (optional) |
The action you want performed if the condition is |
Syntax 2 (the multiline format):
|
1 2 3 4 5 6 7 8 |
IF condition1 THEN action1 { ELSEIF condition2 THEN action2 . . . } { ELSE action3 } END IF |
|
Parameter |
Description |
|---|---|
|
condition1 |
The first condition you want to test. |
|
action1 |
The action you want performed if condition1 is true. |
|
condition2 (optional) |
The condition you want to test if condition1 is |
|
action2 |
The action you want performed if condition2 is true. |
|
action3 (optional) |
The action you want performed if none of the |
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
Example 1
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) |
Example 2
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 2 |
IF sle_State.text="TX" THEN & MessageBox("Hello","Tex") |
Example 3
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 2 3 |
IF w_first.X > w_second.X THEN w_first.X = 0 END IF |
Example 4
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 true
|
1 2 3 4 5 6 7 8 9 10 |
IF X=Y THEN Beep(2) ELSEIF X=Z THEN Show (lb_parts); lb_parts.SetState(5,TRUE) ELSEIF X=" " THEN Show (lb_choose) ELSE Hide(cb_empty) Show(cb_full) END IF |