我的问题是,我试图让用户只能输入“a,b,c或d”。如果他们没有输入这四个字母中的一个,而只是用户只能输入这些字母,我宁愿让它出错。我只能找到与数字数据类似的资源(使用try catch)。任何网站或提示将是伟大的。验证字符串用户输入
If String.Compare(TextBox2.Text, "a", True) = 0 AndAlso String.Compare(TextBox21.Text, "a", True) = 0 Then
'MessageBox.Show("A")
totCorrect = totCorrect + corAns
ElseIf String.Compare(TextBox2.Text, "b", True) = 0 AndAlso String.Compare(TextBox21.Text, "b", True) = 0 Then
'MessageBox.Show("B")
totCorrect = totCorrect + corAns
ElseIf String.Compare(TextBox2.Text, "c", True) = 0 AndAlso String.Compare(TextBox21.Text, "c", True) = 0 Then
'MessageBox.Show("C")
totCorrect = totCorrect + corAns
ElseIf String.Compare(TextBox2.Text, "d", True) = 0 AndAlso String.Compare(TextBox21.Text, "d", True) = 0 Then
'MessageBox.Show("D")
totCorrect = totCorrect + corAns
Else
totWrong = totWrong + wrgAns
Label13.Visible = True
End If
愚蠢的问题,但如果你希望用户只选择A,B,C或d,为什么不使用组合框代替文本框?那么你将不必做所有这些检查... – 2013-03-27 01:06:42