|
|
Title | Make a numeric field using the KeyPress event handler |
Keywords | numeric field, KeyPress, locked TextBox |
Categories | Controls |
|
|
By Ferdie.
I have been using a function for some time now, that I think does the same trick,
without so much code:
|
|
Public Function check_key_press(v1)
' check for valid characters
' from a "KeyPress" event. (chr(8)=backspace)
' where v1 is the keyascii from a keypress event
If InStr(1, "1234567890-+." & Chr(8), Chr(v1)) Then
check_key_press = v1
Else
check_key_press = 0
End If
End Function
|
|
I would use the call as such:
|
|
Private Sub text1_keypress(KeyAscii As Integer)
KeyAscii = check_key_press(KeyAscii)
End Sub
|
|
[Note that my book Custom Controls Library shows how to make field controls that do this sort of thing, though not this way.]
|
|
|
|
|
|