Microsoft Office Tutorials and References
In Depth Information
Controlling Execution
The Select Case construct
The Select Case construct is useful for choosing among three or more options. this construct
also works with two options and is a good alternative to using If-Then-Else . The syntax for
Select Case is as follows:
Select Case testexpression
[Case expressionlist–n
[Case Else
End Select
The following example of a Select Case construct shows another way to code the GreetMe
examples presented in the preceding section:
Function GreetMe()
Select Case Time
Case Is < 0.5
GreetMe = “Good Morning”
Case 0.5 To 0.75
GreetMe = “Good Afternoon”
Case Else
GreetMe = “Good Evening”
End Select
End Function
And here’s a rewritten version of the Discount function from the previous section, this time
using a Select Case construct:
Function Discount2(quantity)
Select Case quantity
Case Is <= 5
Discount2 = 0
Case 6 To 24
Discount2 = 0.1
Case 25 To 49
Discount2 = 0.15
Case 50 To 74
Discount2 = 0.2
Case Is >= 75
Discount2 = 0.25
End Select
End Function
Any number of instructions can be written below each Case statement; they all execute if that
case evaluates to TRUE.
Search JabSto ::

Custom Search