I've written a small code that converts binary numbers into hex and decimal numbers. I want to restricting user input to just 0's and 1's but I'm having a bit of trouble.
Please can you help me.
Sarah Jamerson
Printable View
I've written a small code that converts binary numbers into hex and decimal numbers. I want to restricting user input to just 0's and 1's but I'm having a bit of trouble.
Please can you help me.
Sarah Jamerson
Put this into the keypress event of the control.
This locks out all keys except the 0 or 1 key. You might want to let them press the backspace key. If so then add a condition of "keyascii <> 8".Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
'if the key pressed is not 1 or 0 then set keyascii = 0.
If (keyascii <> 48) And (keyascii <> 49) then
KeyAscii = 0
End If
End Sub
Iain.
u can use the following code in the keypress event of ur textbox:
-----------------------------
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not (KeyAscii = 48 Or KeyAscii = 49 Or KeyAscii = 8) Then
KeyAscii = 0
End If
End Sub
-----------------------------
48 --> ascii vslue of zero
49 --> ascii vslue of one
48 --> ascii vslue of backspace
This should work.