|
-
Mar 9th, 2000, 06:51 PM
#1
Thread Starter
New Member
I want a text box to only accept letters & numbers. I dont want to use a masked edit box as this limits the length of the text to be entered. I assume I have to use Win32 api setwindowlong, etc. Can anyone help?
-
Mar 9th, 2000, 08:33 PM
#2
Hyperactive Member
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii >= 48 And KeyAscii <= 57 Then
'this means it's a number
ElseIf KeyAscii >= 65 And KeyAscii <= 90 Then
'this means it's a capital letter
ElseIf KeyAscii >= 97 And KeyAscii <= 122 Then
'this means it's a lower case letter
Else
KeyAscii = 0 'it won't write anything to the text box.
'this means it's a different character
End If
End Sub
in the ELSE where I set KeyAscii = 0 you could put a message box telling them they entered an invalid character.
-
Mar 9th, 2000, 08:35 PM
#3
Hyperactive Member
Hello DHorton,
Hopefully this will help you.
Private Sub Text1_KeyPress(KeyAscii As Integer)
'character Ascii
'0 - 9 48 - 57
'A - Z 65 - 90
'a - z 97 - 122
If Not (KeyAscii >= 48 And KeyAscii <= 57 Or KeyAscii >= 65 And KeyAscii <= 90 Or KeyAscii >= 97 And KeyAscii <= 122) Then KeyAscii = 0
End Sub
Nice regards,
Michelle.
-
Mar 9th, 2000, 10:42 PM
#4
Lively Member
or...
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Is <= 32, 48 To 57, 65 To 90, 97 To 122
KeyAscii = KeyAscii
Case Else
KeyAscii = 0
End Select
End Sub
the is <= 32 is to let the user use the control keys
backspace, delete, etc....
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
|