Home >>VB.Net Programs >VB.Net program to use a comma ',' to use multiple options in 'select case'

VB.Net program to use a comma ',' to use multiple options in 'select case'

Write a VB.Net program to use a comma ',' to use multiple options in 'select case'

Here, we can describe a case select of many options separated by a "," operator comma.

Program :

Below is the source code for using the comma ",” to use several options in the 'select case' section. The program given is compiled and successfully executed.

Example


Module Module1
    Sub Main()
        Dim choice As Char
        Console.WriteLine("**************************")
        Console.WriteLine("     a: India")
        Console.WriteLine("     b: Australia")
        Console.WriteLine("     c,d: USA")
        Console.WriteLine("**************************")
        Console.Write("Select your country: ")
        choice = Char.Parse(Console.ReadLine())
        Select Case choice
            Case "a"
                Console.WriteLine("India")
            Case "b"
                Console.WriteLine("Australia")
            Case "c", "d"
                Console.WriteLine("USA")
            Case Else
                Console.WriteLine("Invalid choice")
        End Select
    End Sub
End Module
	
Output:
***************************
a: India
b: Australia
c,d: USA
***************************
Select your country: d
USA

Explanation:

We created a Module1 module in the program above that contains the Main() method. We created a variable choice for Character Type in the Main() method.

Console.WriteLine("***************************")
Console.WriteLine("     a: India")
Console.WriteLine("     b: Australia")
Console.WriteLine("     c,d: USA")
Console.WriteLine("***************************")
Console.Write("Select your country: ")
choice = Char.Parse(Console.ReadLine())

In the above code, we read a character for selection.

Select Case choice
    Case "a"
        Console.WriteLine("India")
    Case "b"
        Console.WriteLine("Australia")
    Case "c", "d"
        Console.WriteLine("USA")
    Case Else
        Console.WriteLine("Invalid choice")
End Select

We used "select case" in the above code, where we specified multiple cases according to the choices given to select an option. We used the comma "," operator here in a single "case" to use multiple options. If the wrong choice is entered, and is not given, then the "Case Else" will be executed.


No Sidebar ads