Question

In the text box, I only want a 3 number combination of 0 and 1 as 011,110,111,001, etc. How can I write to check individual component(from three numbers) is 0 or 1, and specify this for checking error? I want to have a if statement if possible. For example, If the number is 015, this message will be shown.

MsgBox("Please Insert a combination of 0,1 into the text box.")

Was it helpful?

Solution

I would simply restrict character entry to zeroes and ones as the user enters them, and limit the length. You'll have to adjust this code for the proper If checks; I'm a C# guy, not a VB guy.

Private Sub TextBox1_KeyPress(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyPressEventArgs) Handles TextBox1.KeyPress
    If e.KeyChar <> ChrW(Keys.Back) Then
        If Textbox1.Length < 3 and (e.KeyChar = "0" or e.KeyChar = "1") Then
        Else
            e.Handled = True
        End If
    End If
End Sub
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top