If...Then...Else Statements

Define several blocks of statements and the conditions that determine which block is executed. You can use a single-line syntax or multiple lines in a block. Not available in expressions.

Syntax

If condition Then statements [Else statements]
If condition 
   Then statements  End   [Else statements  End]

condition is a numeric value or comparison whose value determines the program flow. If condition is true, the Then clause is taken. If condition is false, the Else clause is taken. If condition is a null value, it evaluates to false.

statements are the statements to be executed depending on the value of condition.

Remarks

You can nest If...Then...Else statements. If the Then or Else statements are written on more than one line, you must use an End statement as the last statement.

Example

Function MyTransform(Arg1, Arg2, Arg3)
* Then and Else clauses occupying a single line each:
   If Arg1 Matches "A..." 
      Then Reply = 1
   Else Reply = 2
* Multi-line clauses: 
   If Len(arg1) > 10 Then
      Reply += 1
      Reply = Arg2 * Reply
   End Else
      Reply += 2
      Reply = (Arg2 - 1) * Reply
   End
* Another style of multiline clauses:
   If Len(Arg1) > 20 
   Then
      Reply += 2
      Reply = Arg3 * Reply
   End 
   Else
      Reply += 4
      Reply = (Arg3 - 1) * Reply
   End
Return(Reply)