|
-
Jun 14th, 2007, 08:28 AM
#1
Thread Starter
Frenzied Member
[RESOLVED] Varify Input
I have code to check the input for specific characters in a text box.
My code catches the incorrect characters, gives a warning, but after the user closes the msgbox, the incorrect character is still entered
I am sure this will be a simple solution but I can't figure it out at the moment.
I have tried the following code in the KeyDown, KeyPress and the KeyUp and I get the same problem each time.
vb Code:
Dim tmpDate As String
tmpDate = txtMembership(Index).Text
Select Case Index
Case 11, 12, 13, 15
Select Case KeyAscii
Case 8 'backspace
Case 47 '/forward slash
Case 48 To 59 'numbers
Case 127 'Delete key
Case Else
MsgBox "You can only enter numbers and the ' / ' seperator when entering dates.", _
vbOKOnly + vbInformation, "Date Format"
'remove last character entered
'Exit Sub
txtMembership(Index).Text = tmpDate
End Select
End Select
-
Jun 14th, 2007, 09:22 AM
#2
Re: Varify Input
just spit balling...I usually test before posting but something like:
txtMembership(Index).Text = mid(tmpDate,1,len(tmpDate) - 1)
-
Jun 14th, 2007, 09:35 AM
#3
Thread Starter
Frenzied Member
Re: Varify Input
Thanks Tyson, but that doesn't work - same problem
-
Jun 14th, 2007, 09:35 AM
#4
Re: Varify Input
Pseudocode:
Code:
If KeyAscii isn't valid Then
error message
KeyAscii = 0
End If
-
Jun 14th, 2007, 09:38 AM
#5
Thread Starter
Frenzied Member
Re: Varify Input
 Originally Posted by MartinLiss
Pseudocode:
Code:
If KeyAscii isn't valid Then
error message
KeyAscii = 0
End If
Thanks Martin, I knew I had done this before, but just couldn't remember the solution
Does it make any difference as to which event I put this in:
KeyDown, KeyUp or KeyPress?
-
Jun 14th, 2007, 09:46 AM
#6
Re: Varify Input
Of those, KeyPress is the only one that gives you the keyascii value so the choice is clear.
-
Jun 14th, 2007, 09:48 AM
#7
Thread Starter
Frenzied Member
Re: Varify Input
 Originally Posted by MartinLiss
Of those, KeyPress is the only one that gives you the keyascii value so the choice is clear.
Should have checked that. I had it in that one, so I hadn't looked again at the other two, both KeyCode.
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
|