|
-
Jun 11th, 2003, 02:46 AM
#1
Thread Starter
Fanatic Member
Numeric characters
Feeling foolish coming up with these silly things but God knows why, the last few days, I've been hamstrung by these trivial errors.
This code does what it is supposed to do only while I step through it. When I run it, whether in the IDE or in the EXE, it does not block non-numeric characters. It let's me enter all kinds of characters.
Code:
Private Sub txtNewIPAddress_KeyDown(KeyCode As Integer, Shift As Integer)
Select Case KeyCode
Case vbKeyBack Or vbKeyDelete Or Asc(".") Or vbKeyHome Or vbKeyEnd
Case 48 To 57
Case Else
KeyCode = 0
End Select
End Sub
-
Jun 11th, 2003, 03:15 AM
#2
I don't fully understand what you are trying to do.
Do you want to assign the KeyCode a "0" whenever it is not between 48 and 57 or one the other Keys?
In this case I would put it like that:
VB Code:
Private Sub txtNewIPAddress_KeyDown(KeyCode As Integer, Shift As Integer)
If Not (KeyCode = vbKeyBack Or KeyCode = vbKeyDelete Or KeyCode = Asc(".") Or KeyCode = vbKeyEnd Or (48 <= KeyCode <= 57)) Then
KeyCode = 0
End If
End Sub
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jun 11th, 2003, 03:53 AM
#3
Thread Starter
Fanatic Member
Thanks. But tell me, what difference would that make? The problem persists. Please remember that it runs while stepping through the code but not while running it.
-
Jun 11th, 2003, 05:09 AM
#4
Addicted Member
if you want to block no numeric characters .. you can use
isNumeric() function...
and then verify the ascii value of it to make sure it is not any of the symbols like "/", "(", etc
why dont you try this?
-
Jun 11th, 2003, 05:35 AM
#5
I made a small change, but I don't think that'S your problem. ???
VB Code:
Private Sub TextBox1_KeyDown(KeyCode As Integer, Shift As Integer)
If (KeyCode = vbKeyBack Or KeyCode = vbKeyDelete Or KeyCode = 190 Or KeyCode = vbKeyEnd Or (48 <= KeyCode And KeyCode <= 57)) Then
Else
KeyCode = 0
End If
End Sub
You're welcome to rate this post!
If your problem is solved, please use the Mark thread as resolved button
Wait, I'm too old to hurry!
-
Jun 11th, 2003, 07:24 AM
#6
I think keydown won't work since there is keyup also. So unless you put the same code in the keyup event you can use the keypress event as following. If you step through the code the keyup event won't fire if I am not mistaken :
VB Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If (KeyAscii < 48 Or KeyAscii > 57) And (KeyAscii <> vbKeyBack) And (KeyAscii <> vbKeyBack) And (KeyAscii <> vbKeyDelete) And (KeyAscii <> Asc(".")) And (KeyAscii <> vbKeyHome) And (KeyAscii <> vbKeyEnd) Then
KeyAscii = 0
End If
End Sub
Has someone helped you? Then you can Rate their helpful post. 
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
|