Microsoft Office Tutorials and References
In Depth Information
y = –2
z = –3
End If
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 presen-
ted 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
Case 6 To 24
Case 25 To 49
DISCOUNT2 = 0.15
Case 50 To 74
Case Is >= 75
DISCOUNT2 = 0.25
Search JabSto ::

Custom Search