PDA

Click to See Complete Forum and Search --> : Limiting letters and numbers in a text box.


danyal711
Dec 4th, 1999, 08:23 AM
what if in a text box i dont want any numbers to be typed in and only 2 letters??? how can i do this??

QWERTY
Dec 4th, 1999, 08:54 AM
I'm not sure what you are asking about, but if you don't want numbers and you allow user to type any two letters then use this:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If IsNumeric(Chr(KeyAscii)) Then
KeyAscii = 0
End If
End Sub

Also set TextBox's MaxLength property to 2
~~~~~~~~~~~

Or if you know what two letters you want the user to enter (for example if you want them to type C for Credit and D for Debit) and you want the user to enter only one letter on a time then use this:

Private Sub Text1_KeyPress(KeyAscii As Integer)
If (Chr(KeyAscii)) <> ["Enter Your First Character"] or (Chr(KeyAscii)) <> _
["Enter Your Second Character"] Then
KeyAscii = 0
End If
End Sub

And set MaxLength Property to 1
~~~~~~~~~~~~~~~~~~

------------------
Visual Basic Programmer (at least I want to be one)
------------------
PolComSoft
You will hear a lot about it.

[This message has been edited by QWERTY (edited 12-04-1999).]