Tag Archives: text input

Limit text input in a Textbox by Visual Basic 6.0

The code snippet below will limit the kind of text your user can put in a textbox control using VB.

'vb 6.0

Function LimitTextInput(ByVal source as Long) As String
'put the next line in the Textbox_KeyPress event
'KeyAscii = LimitTextInput(KeyAscii)
'change Numbers with any other character
Const Numbers$ = "0123456789."'backspace =8

If source <> 8 Then

  If InStr(Numbers, Chr(source)) = 0 Then

    LimitTextInput = 0

    Exit Function



LimitTextInput = source

End Function