Promotic

If...Then...Else - statement of language VBScript

Description:
Conditionally executes a group of statements, depending on the value of an expression.
Syntax:
If condition Then statements [Else elsestatements]


or, you can use the block form syntax:
If condition Then
  [statements]
[ElseIf condition-n Then
  [elseifstatements]]
[Else
  [elsestatements]]
End If


condition Number or text string that evaluates to true or false. If condition is Null, then condition is treated as false.
statements One or more statements separated by colons; executed if condition is true.
condition-n Same as condition
elseifstatements One or more statements executed if the associated condition-n is true.
elsestatements One or more statements executed if no previous condition or condition-n expression is true
Note:
You can use the single-line form (1st syntax) for short, simple tests. However, the block form (2nd syntax) provides more structure and flexibility than the single-line form and is usually easier to read, maintain, and debug.
Tip: The single-row form allows to enter multiple statements, but each of the statements must be separated by "colon" character:
If A > 10 Then A = A + 1 : B = B + A : C = C + B


When executing a block If (2nd syntax), condition is tested. If condition is true, then the statements following Then are executed. If condition is false, then each ElseIf (if any) is evaluated in turn. If a true condition is found, then the statements following the associated Then are executed. If none of the ElseIf statements are true (or there are no ElseIf clauses), then the statements following Else are executed. After executing the statements following Then or Else, execution continues with the statement following End If.
The Else and ElseIf clauses are both optional. You can have as many ElseIf statements as you want in a block If, but none can appear after the Else clause. Block If statements can be nested; i.e. contained within one another.

What follows the Then keyword is examined to determine whether or not a statement is a block If. If anything other than a comment appears after Then on the same line, the statement is treated as a single-line If statement.
A block If statement must be the first statement on a line. The block If must end with an End If statement.

For similar purpose in the JavaScript language is used the statement if...else.
Example:
VBScriptSelect and copy to clipboard

Dim Temperature
' .....
If Temperature > 95 Then
' ...
ElseIf Temperature < 12 Then
' ...
Else
' ...
End If
PROMOTIC 9.0.27 SCADA system documentation MICROSYS, spol. s r.o.

Send page remarkContact responsible person
© MICROSYS, spol. s r.o.