O'Reilly logo

Special Edition Using Microsoft® Visual Basic® .NET by Jeff Spotts, Brian Siler

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required