내 문제는 사용자가 "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를 선택 텍스트 상자? 그렇다면이 모든 검사를 수행 할 필요가 없습니다 ... –