所以即時嘗試讓這個代碼工作,但它不返回代碼的如果喜歡部分 任何值。我不知道爲什麼會發生這種情況。If Like語句沒有輸出?
Private Sub btnDisplay_Click(sender As Object, e As EventArgs) Handles btnDisplay.Click
'display color button click event procedure should display the color of the item
'whos item number is entered by the user.
'all item numbers contain exactly seven characters
'all items are available in four colors: blue, green, red, and white.
'the fourth character in the item number indicates the items color
'as follows: B or b indicates blue etc
'if the item number does not contain 7 charactors OR
'if the forth character is not one of the valid color characters,
'the procedure should display the appropriate message
If txtItem.Text Like "###[bBgGrRrwW]###" Then
If txtItem.Text.Contains("bB") Then
lblColor.Text = "Blue"
ElseIf txtItem.Text.Contains("gG") Then
lblColor.Text = "Green"
ElseIf txtItem.Text.Contains("rR") Then
lblColor.Text = "Red"
ElseIf txtItem.Text.Contains("Ww") Then
lblColor.Text = "White"
End If
ElseIf txtItem.Text IsNot "###[bBgGrRwW]###" Then
MessageBox.Show("Bad Job", "Color Project", MessageBoxButtons.OKCancel,
MessageBoxIcon.Information)
End If
End Sub
什麼是'txtItem.Text'價值? – Steve
確保你明白[Like'的作用是什麼](http://msdn.microsoft.com/en-us/library/swf8kaxw.aspx),[IsNot'的作用](http://msdn.microsoft.com/zh-cn/ com/en-us/library/t3bat82c.aspx)和[Contains'包含的內容](http://msdn.microsoft.com/zh-cn/library/dy85x1sa.aspx)。 – GSerg
txtItem.Text的值是用戶輸入到文本框中的值。我試圖用類似的語句來驗證文本。據我所知,這應該起作用。 – 0000