0

TextBoxの入力を検証して、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への入力は、2進数のみを受け入れる必要があるため、1またはのみ0を許可する必要があります。

4

3 に答える 3

4

ここで使用できLikeます:

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 の範囲にない 1 文字、次に 0 から任意の多数」をテストしています。

于 2013-03-20T20:53:55.687 に答える
0

以下はコードです。このフォーラムに質問を投稿する前に、親切にグーグルしてください。

'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
于 2013-03-20T18:29:31.240 に答える
0

バイナリデータをチェックする関数が見つかりません。しかし、あなたはただのようにチェックすることはできません

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

instr 関数でもできると思います。

于 2013-03-20T18:21:58.033 に答える