|
-
Sep 11th, 2000, 04:50 PM
#1
Thread Starter
Frenzied Member
Code:
If Asc(Char) > 47 And Asc(Char) < 58 Then
'bla bla ba
end if
an error keeps coming up to that line
NXSupport - Your one-stop source for computer help
-
Sep 11th, 2000, 04:57 PM
#2
What error are you getting?
-
Sep 11th, 2000, 05:03 PM
#3
Thread Starter
Frenzied Member
Invalid procedure call or argument (run time error 5)
NXSupport - Your one-stop source for computer help
-
Sep 11th, 2000, 05:04 PM
#4
i am assuming that this is what you want...
in the keypress event put this...
Select Case KeyAscii
Case 8 'backspace key
Case 13 'return key
cmdQuery(1).SetFocus
' control to set focus on enter
Case 48 To 57 ' chr(48) - chr(57)
' only numbers
End Select
-
Sep 11th, 2000, 05:11 PM
#5
If only entering numbers what you want, then you can use the Like operator as well.
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
'Allow backspace, tab and spacebar to be pressed
If KeyAscii = 8 Or KeyAscii = 9 Or KeyAscii = 32 Then Exit Sub
If Not Chr(KeyAscii) Like "#" Then KeyAscii = 0
End Sub
-
Sep 11th, 2000, 05:22 PM
#6
Thread Starter
Frenzied Member
wait a sec, cna you correct my first line of code? becuase I need to make it so that you can only enter numbers and backspaces into a texbox
NXSupport - Your one-stop source for computer help
-
Sep 11th, 2000, 05:28 PM
#7
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case 8 'backspace key
Case 13 'return key
'next control to get focus
control.setfocus
Case 48 To 57 ' chr(48) - chr(57)
' only numbers
Case Else ' nothing else
KeyAscii = 0
End Select
End Sub
[Edited by larryn on 09-11-2000 at 06:31 PM]
-
Sep 11th, 2000, 05:31 PM
#8
Thread Starter
Frenzied Member
can you make it something like:
If Asc(Char) > 47 And Asc(Char) < 58 Then
? that includes Ascii and stuff
NXSupport - Your one-stop source for computer help
-
Sep 11th, 2000, 05:34 PM
#9
Hyperactive Member
Probably Char is empty
If you have not put some value into char, then you will get the error you have mentioned.
I suggest you check your logic because the only error I can see possible in your line at runtime is empty variable.
The suggestions mentioned in other replies are a better approach to handling invalid characters on a Text_Change event. Better still in my view is to use the "masked edit control".
Cheers
Paul Lewis
(Back from holiday and looking for something to do)
-
Sep 11th, 2000, 05:37 PM
#10
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 9 Or KeyAscii = 8 Or KeyAscii = 32 Then Exit Sub
If Not (KeyAscii > 47 And KeyAscii < 58) Then KeyAscii = 0
End Sub
-
Sep 11th, 2000, 08:11 PM
#11
_______
<?>
Code:
Option Explicit
'allow for backspace and numbers only
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii = 8 Or _
KeyAscii >= 48 And KeyAscii <= 57 Then
KeyAscii = KeyAscii
Else
KeyAscii = 13
End If
End Sub
"A myth is not the succession of individual images,
but an integerated meaningful entity,
reflecting a distinct aspect of the real world."
___ Adolf Jensen
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
|