sas

Topic: ASP


Select Case Statement

Select Case is similar to If..Then..Else statement. Select Case allows us to do various comparisions against one variable that we use throughout the whole statement. Select Case is cleaner and easier to understand if you are continually comparing against one variable.

The following sample asks the user to enter a vowel in a textbox and checks the value entered using the the Select Case statement and if true displays some text.

Private Sub IfThen_Click(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles IfThen.Click
If CInt(TextBox1.Text) = 1 Then
Label1.Text = "You entered" & CInt(TextBox1.Text)
ElseIf CInt(TextBox1.Text) = 2 Then
Label1.Text = "You entered" & CInt(TextBox2.Text)
ElseIf CInt(TextBox1.Text) = 3 Then
Label1.Text = "You entered" & CInt(TextBox2.Text)
Else
Label1.Text = "You entered another number"
End If
End Sub

 

 

 

 

 

 

 




The following sample asks the user to enter a vowel in a textbox and checks the value entered using the the Select Case statement and if true displays some text.

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e_
As System.EventArgs) Handles Button1.Click
Select Case TextBox1.Text
Case "a"
Label1.text = "You entered A"
Case "e"
Label1.Text = "You entered E"
Case "i"
Label1.Text = "You entered I"
Case "o"
Label1.Text = "You entered O"
Case "u"
Label1.Text = "You entered U"
End Select
End Sub


 





 

 






Prev