Siebel VB Language Reference > VB Language Reference >
If...Then...Else Statement
This standard VB control structure executes alternative blocks of program code based on one or more expressions. Syntax A
If condition Then then_statement [Else else_statement] Syntax B
If condition Then statement_block [ElseIf expression Then statement_block ]... [Else statement_block ] End If
|
|
condition |
Any expression that evaluates to TRUE (non-zero) or FALSE (zero) |
then_statement |
Any valid single expression |
else statement |
Any valid single expression |
expression |
Any expression that evaluates to TRUE (non-zero) or FALSE (zero) |
statement_block |
0 or more valid expressions, separated by colons (:), or on different lines |
Returns
Not applicable Usage
When multiple statements are required in either the Then or Else clause, use the block version (Syntax B) of the If statement. Example
This example checks the time and the day of the week and returns an appropriate message. Sub Button_Click Dim h, m, m2, w h = hour(now) If h > 18 then m = "Good evening, " Elseif h >12 then m = "Good afternoon, " Else m = "Good morning, " End If w = weekday(now) If w = 1 or w = 7 Then m2 = "the office is closed." Else m2 = "please hold for company operator." End If End Sub
See Also
Do...Loop Statement GoTo Statement On...GoTo Statement Select Case Statement While...Wend Statement
|