Using Select Case

Another way to handle decisions in a program is to use the Select Case statement. It allows you to conditionally execute any of a series of statement groups based on the value of a test expression, which can be a single variable or a complex expression. The Select Case statement is divided into two parts: test expression to be evaluated and a series of Case statements listing the possible values.

How Select Case Works

The Select Case structure is similar to a series of If/Then/ElseIf statements. The following lines of code show the syntax of the Select Case block:

Select Case testvalue 
   Case value1
							statement group 1 
   Case value2
							statement group 2 
End Select 

The first statement of the Select Case block is the Select Case statement ...

Get Special Edition Using Microsoft® Visual Basic® .NET 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.