|
-
Apr 3rd, 2000, 04:26 PM
#1
Thread Starter
Hyperactive Member
Hi,
Could someone please tell me what I'm doing wrong here? The only keys I want the user to be able to press are number 1 to 9 on the keyboard, the subtract key, and the back space key. For some reason I can't understand the subtract key isn't recognised.
Private Sub Text5_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> vbKeyReturn And KeyAscii <> vbKeySubtract And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
Any help would be much appreciated!
-
Apr 3rd, 2000, 05:30 PM
#2
Lively Member
KeyCode Constants (e.g. vbKeySubtract and vbKeyReturn)
are applicable in either KeyDown or KeyUp events but not
on a KeyPress event. You can use the ASCII code equivalent
instead...Thus a minor change in your code will be to use the ASCII code for the minus sign (45) instead of vbKeySubtract...
e.g.
Code:
Private Sub Text5_KeyPress(KeyAscii As Integer)
If Not IsNumeric(Chr(KeyAscii)) And KeyAscii <> 13 _
And KeyAscii <> 45 And KeyAscii <> 8 Then
KeyAscii = 0
End If
End Sub
-
Apr 3rd, 2000, 06:54 PM
#3
Thread Starter
Hyperactive Member
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
|