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

Get Visual Basic® .NET by Example 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.