O'Reilly logo

Visual Basic® .NET by Example by Bob Donald, Gabriel Oancea

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

The Select Case Statement

The Select Case statement is used as a convenient replacement for an If statement with a large number of ElseIf branches. Let's write a simple example to illustrate the use of a Select Case. Your task is to develop a funny oracle that will guess the gender of the user, based on its first name. Create a new console project and name it SelectCaseExample, and then enter the code as shown in the following example.

 Sub Main() Console.Out.WriteLine("I am the Oracle and I will guess your gender") Console.Out.WriteLine("Enter your first name and press <ENTER>: ") Dim s As String s = Console.In.ReadLine() Select Case s Case "Bob" Console.Out.WriteLine("Hi Bob!") Case "Gabriel" Console.Out.WriteLine("You again?!") Case "Jim" ...

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