Dim num As Integer
num = CInt(txtIn.Text)
Select Case num
Case 1
MsgBox("You entered 1",,"")
Case 2 To 5
MsgBox("You entered a number from 2-5",,"")
Case 7,9,11
MsgBox("You entered an odd number from 7-11",,"")
Case Is > 12
MsgBox("You entered a number greater than 12",,"")
Case Else
MsgBox("You entered some other number",,"")
End Select
All of this works like the classic If/ElseIf/Else structure. so we could rewrite the above using If statements:
Dim num As Integer
num = CInt(txtIn.Text)
If num = 1 Then
MsgBox("You entered 1",,"")
ElseIf 2 <= num And num <= 5 Then
MsgBox("You entered a number from 2-5",,"")
ElseIf num = 7 Or num = 9 Or num = 11 Then
MsgBox("You entered an odd number from 7-11",,"")
ElseIf num > 12 Then
MsgBox("You entered a number greater than 12",,"")
Else
MsgBox("You entered some other number",,"")
End If
You can also use Select Case to compare Strings just like you can with If statements.
No comments:
Post a Comment