遇到問題,爲什麼這不會檢查文本框以及選定的顏色。
如果我沒有放置顏色,它會標記「請輸入字段」消息,但是如果我確實選擇了一種顏色,但不在名稱文本框中輸入任何內容,則它會繼續並在msgbox中輸出一個空白字符串。檢查是否爲空VB.NET
代碼是:
Dim newColor As Color
Dim userName As String
Dim notEnoughArguments As String = "Please fill out the fields"
'Click event for button
Private Sub enterBtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles enterBtn.Click
If (userName Is "") Then
MsgBox(notEnoughArguments)
ElseIf (userName Is "" And colorLtb.SelectedItem Is Nothing) Then
MsgBox(notEnoughArguments)
ElseIf (colorLtb.SelectedItem Is Nothing) Then
MsgBox(notEnoughArguments)
Else
userName = txt1.Text
Dim selectedColor As String = colorLtb.SelectedItem.ToString
newColor = Color.FromName(selectedColor)
Dim msgBoxText As String = "Hello " + txt1.Text + "." & vbCrLf + "Changing your color to " + selectedColor + "."
MsgBox(msgBoxText)
Me.BackColor = newColor
End If
End Sub
發現我只檢查,他們倆都做了,但把它們當進入單獨的,如果我們從一個ELSEIF它仍然無法正常工作? - 編輯主文章以顯示新代碼。儘管如此,仍然有同樣的問題。 – 2014-09-11 09:08:37