我的问题是我试图让用户只能输入“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