|
-
Feb 13th, 2008, 01:02 PM
#1
Thread Starter
Frenzied Member
[RESOLVED] make textbox accept string
I would like to allow only string press from keyboad and spacebar are acceptable. How to do that?
-
Feb 13th, 2008, 01:08 PM
#2
Re: make textbox accept string
If I understood you then you wish to disallow numeric input.
If so then try this quicky:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If IsNumeric(Chr(KeyAscii)) Then
KeyAscii = 0
End If
End Sub
-
Feb 13th, 2008, 01:13 PM
#3
Frenzied Member
Re: make textbox accept string
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If InStr(1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ 1234567890", UCase(Chr(KeyAscii)), vbTextCompare) > 0 Then
Else
KeyAscii = 0
End If
End Sub

EDIT : remove or add anything you need to allow/disallow in the string
-
Feb 13th, 2008, 01:19 PM
#4
Re: make textbox accept string
Using InStr will also prevent you from using say BackSpace which is most likely needed for editing.
Here is another variation of what I posted previously:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not (KeyAscii = 32 Or KeyAscii = 8) Then 'allow using spacebar and backspace keys
If Asc(LCase(Chr(KeyAscii))) < 97 Or Asc(LCase(Chr(KeyAscii))) > 122 Then
'disallow anything but alpha chars (Aa-Zz)
KeyAscii = 0
End If
End If
End Sub
-
Feb 13th, 2008, 01:19 PM
#5
Re: make textbox accept string
zeezee,
Can you please explain how that works?
It looks like you are taking the keyboard character entered, temporarily making it upper case and then comparing it to the string "ABCDE........ 1234567890" and if found do nothing but if not found then set KeyAscii to 0 but I don't understand it. Me not too bright today.
-
Feb 13th, 2008, 01:20 PM
#6
Re: make textbox accept string
 Originally Posted by matrik02
I would like to allow only string press from keyboad and spacebar are acceptable. How to do that?
In other words, you do not want to allow numeric input, correct?
-
Feb 13th, 2008, 01:22 PM
#7
Thread Starter
Frenzied Member
Re: make textbox accept string
What the difference with your previous code #2 ?
-
Feb 13th, 2008, 01:24 PM
#8
Thread Starter
Frenzied Member
Re: make textbox accept string
 Originally Posted by Hack
In other words, you do not want to allow numeric input, correct?
Yes.
-
Feb 13th, 2008, 01:26 PM
#9
-
Feb 13th, 2008, 01:33 PM
#10
Re: make textbox accept string
 Originally Posted by matrik02
What the difference with your previous code #2 ?
If you can tell to whom is your question addressed please?
-
Feb 14th, 2008, 01:01 AM
#11
Thread Starter
Frenzied Member
Re: make textbox accept string
Thank you RhinoBull and the other, it work now
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
|