Text problem

Mystical_Moon
09-04-2003, 10:08 AM
When making a text box I would like to know how to stop users from using certain keys by only enabling the letters. If someone would give me the syntax for this it would be greatly appreciated. If there is a misunderstanding in what I would like to know than I will give an example; When setting the max characters for the text box trying to go beyond that limit during runtime creates a beep and does nothing, I would like to get this to happen during my text with other characters and not just all of them so I know that this is possible. All advice is thanked for in advance. Thank You!

00100b
09-04-2003, 10:11 AM
Use the KeyPress event for the TextBox. If the KeyAscii value for the key-press is one that you want to exclude, then issue a Beep and change the KeyAscii value to zero (0).

passel
09-04-2003, 10:17 AM
As 00100b says. I would key on the characters I want to allow, e.g.
Private Sub Text1_KeyPress(KeyAscii As Integer)
Dim a As String
a = Chr$(KeyAscii)
If InStr("abcABC0123456789", a) = 0 Then Beep: KeyAscii = 0
End Sub

Whichever gives you the fewer characters to test for.
This code above essentially says "if the character is not one I allow then..."

Change "=" to "<>" in the "if" line to exclude those characters

Mystical_Moon
09-04-2003, 10:18 AM
Could you give me an example on that? I'm alittle slow on the programming because I haven't really worked with it. Where can I find the ascii key coordinates (Ya know where it says E=89 or something)?

Baradin
09-04-2003, 10:19 AM
Could you give me an example on that? I'm alittle slow on the programming because I haven't really worked with it. Where can I find the ascii key coordinates (Ya know where it says E=89 or something)?


http://www.asciitable.com/

Thereyago

reboot
09-04-2003, 10:20 AM
He just gave you an example.

sPiKie
09-04-2003, 10:35 AM
You can also do this, do see an ASCII Table... Start a new project, add a listbox to it (List1).. Then add this code into the Form_Load event..:

Private Sub Form_Load()
For i = 1 To 255
List1.AddItem i & " = " & Chr(i) 'Add the info
Next i
End Sub

And look above, passel (expert) gaved you an example on the question you asked about ;)

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum