21 | 08 | 2017

Limit Text Input

When using a texbox control you can validate/limit the users input. You can do this by blocking all keys that are not valid. Code below uses a textbox called Text1 and locks all values that are not numeric.

Function ValidateInput(getdata) As String
'**** Code from VisibleVisual.com ******
    Const Numbers$ = "0123456789.##"
    If getdata <> 8 Then 'backspace =8
    If InStr(Numbers, Chr(getdata)) = 0 Then
    ValidateInput = 0
    Exit Function
    End If
    End If
    ValidateInput = getdata
End Function
Private Sub Text1_KeyPress(KeyAscii As Integer)
KeyAscii = ValidateInput(KeyAscii)
End Sub

Sign up now and upload your code to the website.

Help us to continue.....
Articles View Hits
Latest Articles