Microsoft Office Tutorials and References
In Depth Information
block2
End If
condition is a logical expression. If it is True, the statements in block1 are executed. If
condition is False, the statements in block2 are executed. The Else keyword and the second
block of statements are optional. If they are omitted, no statements are executed if condition is
False.
You can test multiple conditions in an If...Then...Else statement by using the ElseIf
keyword. Here’s how this is written:
If condition1 Then
block1
ElseIf condition2 Then
block2
ElseIf condition3 Then
block3
....
Else
block4
End If
There’s no limit to the number of ElseIf s. The testing of the various conditions starts at the top
and works downward. As soon as a True condition is found, the corresponding block of statements
is executed and execution exits the If statement. One block of statements at most will be executed
regardless of how many of the conditions are True.
When you need to test multiple conditions, it is usually easier to use the Select Case statement,
covered next.
Select Case
The Select Case statement evaluates a single expression and compares the result with a series of
templates. If it finds a match, the associated block of statements is executed. The syntax is
Select Case expression
Case template-1
statements-1
Case template-2
statements-2
....
Case template-n
statements-n
Case Else
statements-else
End Select
expression is evaluated and the result is matched against the various templates, in order from
top to bottom. When a match is found, the following block of statements is executed. If no match
Search JabSto ::




Custom Search