×

VB.Net Programs

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

By Nidhi Last Updated : November 16, 2024

Using a comma ',' to use multiple options in 'select case'

Here, we will define a select case with multiple options separated by a comma "," operator.

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

The source code to use a comma "," to use multiple options in "select case" is given below. The given program is compiled and executed successfully.

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

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
Press any key to continue . . .

Explanation:

In the above program, we created a module Module1 that contains a Main() method. In the Main() method, we created a variable choice of Character type.

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

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

VB.Net Basic Programs »


Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.