. . Case. This statement offers a
flexible method for evaluating many known choices:
Select Case expression
Case expressionevaluation
statements
Case Else
elsestatements
End Select
You must always close a Select . . . Case statement with End Select. There are many
options for evaluating Case expressions. You can check for a single value, a range of values, or
multiple values:
Select Case x
Case Is <= 0
y = 1
Case 1 - 5
y = 10
Case 6, 7, 8
y = 100
Case 10
y = 20
End Select
You can also use Case Is with an operator (like <=) to evaluate the expression. The Is keyword
in a Select . . . Case statement is not related to the Is operator used to evaluate
reference types. As soon as a Case is evaluated to be true, the statements following it are executed,
and then flow control moves to the statement after End Select.
CHAPTER 2 n VB 2008 SYNTAX 30
Iteration and Looping Constructs
VB is no different than other languages in that it provides constructs for iterating and looping
over items until a condition is met. Let??™s take a quick tour of these statements.
For Each . . .Next
The For Each . . . Next statement allows you to iterate over a collection of objects and execute
statements for each element in the collection. The For Each .
Pages:
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83