|
-
Aug 22nd, 2000, 10:46 AM
#1
Thread Starter
PowerPoster
Two things I'm trying to do:
Limit input to digits 0-9 and
on the 2nd number, add a hyphen so the user won't have to type.
My hopefully end result would be 34-123.
Any help would be appreciated.
-
Aug 22nd, 2000, 10:54 AM
#2
Frenzied Member
No Problem
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) Then
KeyAscii = 0
ElseIf Len(Text1.Text) = 2 Then
Text1.Text = Text1.Text & "-"
Text1.SelStart = 3
End If
End Sub
-
Aug 22nd, 2000, 10:57 AM
#3
Try this.
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then KeyAscii = 0
If Len(Text1) = 2 Then Text1.SelText = "-"
End Sub
-
Aug 22nd, 2000, 11:11 AM
#4
Thread Starter
PowerPoster
Thanks guys. It works just like I needed.
-
Aug 22nd, 2000, 11:29 AM
#5
Thread Starter
PowerPoster
Sorry to be a pain but what if I the backspace key to be active? Better yet, is there a chart of KEYASCII codes so I can know what's what?
-
Aug 22nd, 2000, 11:37 AM
#6
Frenzied Member
the backspace key is 8
so enclose everything in the Keypress event in an If Not (KeyAscii = 8) Then ... Endif block.
If you want to get different keyasciis the easiest way is to add another textbox to your form and add this
Code:
Private Sub Text2_KeyPress(KeyAscii As Integer)
Text2.Text = KeyAscii
KeyAscii=0
End Sub
then run your program , put the curser in the textbox and press the key you want, the correct code will apear in the textbox
-
Aug 22nd, 2000, 11:42 AM
#7
James Stanich,
If you are looking for a chart,
MSDN has topics under Character Sets. It lists the charcters along with their charcter codes.
-
Aug 22nd, 2000, 11:51 AM
#8
Thread Starter
PowerPoster
-
Aug 22nd, 2000, 12:33 PM
#9
Or even better; use the constant values:
- vbKeyBack
- vbKeyReturn
- vbKeyEscape
- vbKeyA
- vbKeyB
- ...
- vbKeyF1
- vbKeyF2
- ...
And so on...
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
|