Vb6 VB验证文本框输入是否为二进制数

Vb6 VB验证文本框输入是否为二进制数,vb6,Vb6,我试图验证文本框的输入,以确保它是一个二进制数。到目前为止,我得到的是: Private Sub Command1_Click() Dim b() As Byte b = Text1.Text If Not IsByte (b) Then Text3 = "Wrong input" Else Text3 = "CRC is generated" ' checksum.Text = Text1.Text Xor Text2.Text ' Trans(2)

我试图验证文本框的输入,以确保它是一个二进制数。到目前为止,我得到的是:

Private Sub Command1_Click()
 Dim b() As Byte
 b = Text1.Text

 If Not IsByte (b) Then
    Text3 = "Wrong input"
    Else
    Text3 = "CRC is generated"
  '  checksum.Text = Text1.Text Xor Text2.Text
   ' Trans(2).Text = (Text1.Text) + (checksum.Text)
 End If

Text1中的输入应该只接受二进制数,因此只允许
1
0

即使我找不到检查二进制数据的函数。但是你不能像这样检查一下吗

   If textbox1.text = 1 or textbox1.text = 2

我想你也可以使用instr函数

即使我也找不到检查二进制数据的函数。但是你不能像这样检查一下吗

   If textbox1.text = 1 or textbox1.text = 2

我想你也可以使用instr函数

下面是代码。在向本论坛发布任何问题之前,请您友好地搜索

'will only allow 0 and 1
Private Sub Text1_KeyPress(KeyAscii As Integer)
 Select Case KeyAscii
    Case vbKey0 To vbKey1
    Case Else
        KeyAscii = 0
    End Select
End Sub

' will validate if its numeric and you can further check for 0 or 1
Private Sub Command1_Click()
        If Not IsNumeric(Text1.Text) Then
            MsgBox "Please enter numbers only.", vbInformation
            'you may also consider erasing it
            Text1.Text = ""
        End If
    End Sub

下面是代码。在向本论坛发布任何问题之前,请您友好地搜索

'will only allow 0 and 1
Private Sub Text1_KeyPress(KeyAscii As Integer)
 Select Case KeyAscii
    Case vbKey0 To vbKey1
    Case Else
        KeyAscii = 0
    End Select
End Sub

' will validate if its numeric and you can further check for 0 or 1
Private Sub Command1_Click()
        If Not IsNumeric(Text1.Text) Then
            MsgBox "Please enter numbers only.", vbInformation
            'you may also consider erasing it
            Text1.Text = ""
        End If
    End Sub

您可以在此处使用类似的

Private Sub Command1_Click()
    If Len(Text1.Text) = 0 Or Text1.Text Like "*[!0-1]*" Then
        MsgBox "bad binary string"
    Else
        MsgBox "good binary string"
    End If
End Sub

此模式正在测试“0到任意多个字符,后跟一个不在0到1范围内的字符,然后是0到任意多个字符。”

您可以在此处使用类似的

Private Sub Command1_Click()
    If Len(Text1.Text) = 0 Or Text1.Text Like "*[!0-1]*" Then
        MsgBox "bad binary string"
    Else
        MsgBox "good binary string"
    End If
End Sub


此模式测试的是“0到多个字符,后跟一个不在0到1范围内的字符,然后是0到多个字符。”

是的,谢谢你的作品,那么如何尽可能长时间地初始化Text1?你能接受同样会提高你声誉的答案吗?接受答案不需要任何声誉。这是唯一需要声誉的投票。请接受你信任这里的人的答案。只需点击标记。是的,谢谢你的作品,那么如何尽可能长地初始化Text1?你能接受答案吗?接受答案也会增加你的声誉吗?接受答案不需要任何声誉。这是唯一需要声誉的投票。请接受你信任这里的人的答案。只需点击标记。@Ricky-2135您的mozilla崩溃了,但您仍然设法将此问题发布到stack overflow。@Ricky-2135请在您的mozilla或chrome崩溃之前接受此答案。我想,但据说需要15个声誉才能投票,对不起,我刚登记today@Ricky-不用担心:-)这就是我要去的答案with@Ricky-2135您的mozilla崩溃了,但您仍然设法将此问题发布到stack overflow。@Ricky-2135请在您的mozilla或chrome崩溃之前接受此答案。我想,但它说需要15个声誉才能投票,对不起,我刚登记today@Ricky-不用担心:-)这将是我的答案,谢谢,真的很有帮助谢谢,真的很有帮助