ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT

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

Here, we are going to learn how to use a comma ',' to use multiple options in 'select case' in VB.Net?
Submitted by Nidhi, on December 03, 2020

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

Program/Source Code:

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 »



ADVERTISEMENT



ADVERTISEMENT



Comments and Discussions

ADVERTISEMENT

ADVERTISEMENT

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT

Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.