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):

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 true. The action must be a single statement on the same line as the rest of the IF statement.

action2 (optional)

The action you want performed if the condition is false. The action must be a single statement on the same line as the rest of the IF statement.


Syntax 2 (the multiline format):

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. The action can be a statement or multiple statements that are separated by semicolons or placed on separate lines. At least one action is required.

condition2 (optional)

The condition you want to test if condition1 is false. You can have multiple ELSEIF...THEN statements in an IF...THEN control structure.

action2

The action you want performed if condition2 is true. The action can be a statement or multiple statements that are separated by semicolons or placed on separate lines.

action3 (optional)

The action you want performed if none of the preceding conditions is true. The action can be a statement or multiple statements that are separated by semicolons or placed on separate lines.


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:

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:

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:

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

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