Selecting with Select Case

The Select Case statement is better suited to checking for multiple conditions than is If, even when utilizing the logical operators. The use of more than three or four embedded If...Else statements results in a complicated program. You get into messy logic such as “If this is true, then if this is true, then if one more thing is true, then do something, otherwise…” Here is the Select Case statement's format:

Select Case Expression
  Case expressionMatch
						Block of one or more Visual Basic statements
  [ Case expressionMatch1
						Block of one or more Visual Basic statements]
  [ Case expressionMatch2
						Block of one or more Visual Basic statements]
      :
  [ Case expressionMatchN
						Block of one or more Visual Basic statements] [Case Else ...

Get Absolute Beginner's Guide to Programming, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.