VB.NET tutorial: Conditional Statements- Select Case


Conditional Statements-Select Case

Select case statement is used to test multiple choices. Here is the general form of the select case statement.


Select case variable
  case val1
            statements
  case val2
            statements
  case val3
            statements
…………
  case else
            statements
End select
 
Example:


Module Module1
    Sub Main()
        Dim x As Integer

        Console.WriteLine("Please enter your number from 1 to 3")
        x = CInt(Console.ReadLine())
        Select Case x
            Case 1
                Console.WriteLine("You entered 1")
            Case 2
                Console.WriteLine("You entered 2")
            Case 3
                Console.WriteLine("You entered 3")
            Case Else
                Console.WriteLine("Invalid!")
        End Select
    End Sub
End Module


Comments

CAPTCHA image




This website intents to provide free and high quality tutorials, examples, exercises and solutions, questions and answers of programming and scripting languages:
C, C++, C#, Java, VB.NET, Python, VBA,PHP & Mysql, SQL, JSP, ASP.NET,HTML, CSS, JQuery, JavaScript and other applications such as MS Excel, MS Access, and MS Word. However, we don't guarantee all things of the web are accurate. If you find any error, please report it then we will take actions to correct it as soon as possible.