我目前在对我的二进制加法器进行验证检查时遇到错误,但只能检查它的 1 或 0。我希望它检查文本框是否包含从 2 到 9 以及从 a 到 z 的所有内容。我的代码目前是:
Dim errorpass As Integer = 2
Dim decnum As Integer = 2
Dim errormsg As String = "ERROR:" + vbNewLine
'Start of Error Checking
'Checking if either textbox contains anything
If TextBox1.Text = "" Or TextBox2.Text = "" Then
errormsg += ("Please enter some form of input." + vbNewLine)
errorpass = 1
'Checking if either textbox are numbers
ElseIf Not (IsNumeric(TextBox1.Text) Or IsNumeric(TextBox2.Text)) Then
errormsg += ("Please enter a number." + vbNewLine)
errorpass = 1
'Checking if either textbox contains 1's or 0's
For i = 2 To 9
If TextBox1.Text.Contains(decnum) Or TextBox2.Text.Contains(decnum) Then
errormsg += ("Please enter binary." + vbNewLine)
errorpass = 1
ElseIf Not TextBox1.Text.Contains("1" Or "0") Or TextBox2.Text.Contains("1" Or "0") Then
errorpass = 1
If decnum = 9 Then
decnum = 2
Else
decnum += 1
End If
Else
errorpass = 2
End If
Next
End If
'Processing the request
If errorpass = 1 Then
MsgBox(errormsg, MsgBoxStyle.Exclamation, Title:="ERROR PROCESSING YOUR REQUEST")
ElseIf errorpass = 2 Then
'Adder
TextBox3.Text = Convert.ToString(Convert.ToInt32(TextBox1.Text, 2) + Convert.ToInt32(TextBox2.Text, 2), 2)
End If
errorpass = 2
谢谢 :)