●Select Case程式區塊比If程式區塊提供了更多的可能性:
●使用字串作為Select Case區塊的條件:
●多個條件可以對應到相同的結果:
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim unknow As Integer = 5
TextBox2.Text = CStr(unknow)
Select Case unknow
Case 0
TextBox1.Text = "Zero"
Case 1
TextBox1.Text = "One"
Case 2
TextBox1.Text = "Two"
Case 3
TextBox1.Text = "Three"
Case 4
TextBox1.Text = "Four"
Case 5
TextBox1.Text = "Five"
Case 6
TextBox1.Text = "Six"
Case 7
TextBox1.Text = "Seven"
Case 8
TextBox1.Text = "Eight"
Case 9
TextBox1.Text = "Nine"
Case Else
TextBox1.Text = "Unknow"
End Select
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim unknow As String = "seven"
TextBox2.Text = CStr(unknow)
Select Case unknow
Case "zero"
TextBox1.Text = "0"
Case "one"
TextBox1.Text = "1"
Case "two"
TextBox1.Text = "2"
Case "three"
TextBox1.Text = "3"
Case "four"
TextBox1.Text = "4"
Case "five"
TextBox1.Text = "5"
Case "six"
TextBox1.Text = "6"
Case "seven"
TextBox1.Text = "7"
Case "eight"
TextBox1.Text = "8"
Case "nine"
TextBox1.Text = "9"
Case Else
TextBox1.Text = "Unknow"
End Select
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
Dim unknow As Integer = 5
TextBox2.Text = CStr(unknow)
Select Case unknow
Case 0
TextBox1.Text = "Zero"
Case 1, 3, 5, 7, 9
TextBox1.Text = "Odd"
Case 2, 4, 6, 8, 10
TextBox1.Text = "Even"
Case Else
TextBox1.Text = "Unknow"
End Select
End Sub
End Class
沒有留言:
張貼留言