|
-
Oct 22nd, 2003, 09:16 PM
#1
Thread Starter
Hyperactive Member
[SOLVED]Easy! Restrict textbox to just numbers and letters.
I know this is an easy one. I have found the answere, but It wasnt quite what i wanted, and it didnt work for me. Can I have some quick help thanks!
Last edited by squakMix; Oct 22nd, 2003 at 09:39 PM.
-squaK
-
Oct 22nd, 2003, 09:21 PM
#2
Post the code you think is close, and identify the deficiencies.
(This question has been answered many, many times before)
Bruce.
-
Oct 22nd, 2003, 09:25 PM
#3
Thread Starter
Hyperactive Member
This code doesnt work. When i enter a normal character into the textbox, it shows nothing:
VB Code:
Private Sub Text2_KeyPress(KeyAscii As Integer)
If Not (KeyAscii > 47 And KeyAscii < 58) Or (KeyAscii > 64 And KeyAscii < 91) Or (KeyAscii > 96 And KeyAscii < 123) Or (KeyAscii = 95) Then
KeyAscii = 8
End If
I also want to be able to do NON upper case letters also.
-
Oct 22nd, 2003, 09:38 PM
#4
You wern't evaluating all other NOT's, so try:
VB Code:
Option Explicit
Private Sub Text2_KeyPress(KeyAscii As Integer)
If Not ((KeyAscii > 47 And KeyAscii < 58) Or (KeyAscii > 64 And KeyAscii < 91) Or (KeyAscii > 96 And KeyAscii < 123) Or (KeyAscii = 95)) Then
KeyAscii = 0
End If
End Sub
Bruce.
-
Oct 22nd, 2003, 09:39 PM
#5
Thread Starter
Hyperactive Member
Thanks. That's what i needed.
-
Oct 22nd, 2003, 09:43 PM
#6
To clarify: I enclosed the whole 'Or AND' structure (with ()), and if that
was evaluated, then send KeyAscii = 0.
Bruce.
-
Oct 22nd, 2003, 09:50 PM
#7
Although that works for the user typing in the TextBox, you should also check the data thats Cut 'n' Pasted!
One (probably the best) method is to use the Text2_Validate() Event, and if there is an unwanted character, then highlight it and
set the Validation's Cancel = False (kepping the Focus in the TextBox until its correct)
Bruce.
-
Oct 22nd, 2003, 10:01 PM
#8
Thread Starter
Hyperactive Member
with the coding you sent me, the user CANT cut and paste! it doesnt allow for ctrl.
-
Oct 22nd, 2003, 10:02 PM
#9
Thread Starter
Hyperactive Member
...If the user uses the mouse, I have coding that says something like "If len(text2.text) = 0 then"...
-
Oct 22nd, 2003, 10:04 PM
#10
Originally posted by squakMix
with the coding you sent me, the user CANT cut and paste! it doesnt allow for ctrl.
Ahhh, I should have checked that
-
Oct 22nd, 2003, 10:10 PM
#11
Originally posted by squakMix
...If the user uses the mouse, I have coding that says something like "If len(text2.text) = 0 then"...
Not too sure if you indend that (above) to counter the use of the Mouse|Paste....
I was able to paste unwanted characters using the Right Mouse Button.
Again, you may have taken care of that.
-
Oct 22nd, 2003, 10:23 PM
#12
Thread Starter
Hyperactive Member
yea, My actual Coding Has MANY more lines.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|