Select Case Statement in Visual Basic .Net

Download
Download is available until [expire_date]
  • Version
  • Download 41
  • File Size 63.40 KB
  • File Count 1
  • Create Date April 6, 2016
  • Last Updated April 6, 2016

Select Case Statement in Visual Basic .Net

Select Case Statement in Visual Basic .Net

The format of the Select Case control structure is show below:
Select Case expression
Case value1
Block of one or more VB statements
Case value2
Block of one or more VB Statements
Case value3
.
.
Case Else
Block of one or more VB Statements
End Select

The program will allow you to enter a number from 1 to 5; the program will then return a case result based on the number entered.

Source code:

Public Class Form1
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If TextBox1.Text = "" Or IsNumeric(TextBox1.Text) = False Then
            MessageBox.Show("Enter an integer")
            TextBox1.Focus()
        Else
            Select Case TextBox1.Text
                Case 1
                    Label2.Text = TextBox1.Text & " is " & "Visual Basic 6"
                Case 2
                    Label2.Text = TextBox1.Text & " is " & "Visual Basic .Net"
                Case 3
                    Label2.Text = TextBox1.Text & " is " & "PHP"
                Case 4
                    Label2.Text = TextBox1.Text & " is " & "Java"
                Case 5
                    Label2.Text = TextBox1.Text & " is " & "C#"
            End Select
        End If
    End Sub
End Class
, , ,

Post navigation

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.