您好我一直试图让用户输入各种信息(文本框,组合框,日期选择器)并单击按钮,所有输入信息都显示在一个消息框中。此外,我正在尝试创建验证,其中每个字段必须包含某种输入/字符而不是在显示所有输入的消息框出现之前为空。
Dim s, sOut As String
Dim x As System.Xml.XmlElement = cbEval.SelectedItem
If x Is Nothing _
OrElse String.IsNullOrEmpty(txtTotal.Text) _
OrElse String.IsNullOrEmpty(cbEval.SelectedItem) _
OrElse DatePicker1.SelectedDate.Value Is Nothing Then
MessageBox.Show("Please fill in any empty fields.")
Else
sOut = String.Format("Evaluator Name: {0}" & Environment.NewLine() & _
"Text: {1}" & Environment.NewLine() & _
"CbValue: {2}" & Environment.NewLine() & _
"Date3: {3}", _
x.InnerText, txtTotal.Text, cbEval.SelectedItem, DatePicker1.SelectedDate.Value.ToShortDateString())
MessageBox.Show(sOut)
End If
我遇到了关于datepicker的错误:“操作符不接受Date的操作数类型”和“不接受布尔类型”的组合框。
答案 0 :(得分:0)
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
'-----------------------------Check if all Fields are occupied-------------------------
if TextBox1.Text <> "" And TextBox2.Text <> "" And ComboBox1.Text <> "" Then
Dim Information As String = ""
Information = "Your Name is: " & TextBox1.Text & " And Your Living in: " & TextBox2.Text & " Your Favorite Animal is: " & ComboBox1.text & " The Date and Time is Now: " & DateTimePicker1.Value
MessageBox(Information)
Else
MessageBox("Please Fill Out all the Information")
End If
End Sub
试试这个...
答案 1 :(得分:0)
If txtTotal.Text <> "" And txtComments.Text <> "" And cbEval.Text <> "" Then
Dim Information As String = ""
Information = "Your Name is: " & txtTotal.Text & " And Your Living in: " & txtComments.Text & " Your Favorite Animal is: " & cbEval.Text & " The Date and Time is Now: " & DatePicker1.SelectedDate
MessageBox.Show(Information)
Else
MessageBox.Show("Please Fill Out all the Information")
End If
End Sub
非常感谢你!