Limit text input in a Textbox by Visual Basic 6.0

Click Star to Rate Post
1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
 

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

  EndIf

EndIf

LimitTextInput = source

End Function

Leave a Reply