As we have seen, the If...Then...
construct is used to perform
different tasks based on different possibilities. An alternative
construct that is often more readable is the Select
Case
statement,
whose syntax is:
Select Case testexpression Case value1 ' statements to execute if testexpression = value1 Case value2 ' statements to execute if testexpression = value2 . . . Case Else ' statements to execute otherwise End Select
Note that the Case
Else
part is
optional. To illustrate, the following code is the Select
Case
version of Example 12-1 in Chapter 12 (see the discussion of
the Section 12.4.3)
that displays the type of a file based on its extension. I think you
will agree that this is a bit more readable than the previous
version: