Vb.net 如果文本不是指定的文本之一,如何显示消息框?
这是我的密码:Vb.net 如果文本不是指定的文本之一,如何显示消息框?,vb.net,visual-studio-2008,Vb.net,Visual Studio 2008,这是我的密码: Dim Seat As String Seat = txtSeat.Text.ToUpper If Seat = "BOX" Then txtPrice.Text = FormatCurrency(75) ElseIf Seat = "PAVILION" Then txtPrice.Text = FormatCurrency(30) ElseIf Seat = "LAWN" Then tx
Dim Seat As String
Seat = txtSeat.Text.ToUpper
If Seat = "BOX" Then
txtPrice.Text = FormatCurrency(75)
ElseIf Seat = "PAVILION" Then
txtPrice.Text = FormatCurrency(30)
ElseIf Seat = "LAWN" Then
txtPrice.Text = FormatCurrency(21)
End If
我的痛苦是,当用户没有键入指定的单词时,我需要显示一个信息/错误框。因此,如果我改为键入“cat”,则会出现一个消息框,显示“请改为键入列表中的一个座位:)”
编辑:
那很有效,谢谢 请参见
MessageBox.Show()
,假设这是一个WinForms上下文。如果是web,请尝试jQueryUI的对话框
我知道您已经有了答案,但这里是您的答案,使用“选择案例”而不是所有的If语句
Else
MessageBox.Show("Please instead type one of the seats in the list :)")
Dim Seat As String
Seat = txtSeat.Text.ToUpper
Select Case Seat
Case "BOX"
txtPrice.Text = FormatCurrency(75)
Case "PAVILION"
txtPrice.Text = FormatCurrency(30)
Case "LAWN"
txtPrice.Text = FormatCurrency(21)
Case Else
MessageBox.Show("Please instead type one of the seats in the list :)")
End Select
而不是一个文本框,用户必须精确地键入某个字符串(这意味着不允许拼写错误!),您可以考虑使用不同的控件,如选项按钮或组合框。这样,用户就可以从预定义的列表中选择适当的选项。不存在拼写错误的风险,他们可以在前面看到一个选项列表。像这样的东西对用户友好性和易用性有很大帮助。只是想一想。。。