|
-
Sep 16th, 2000, 08:12 AM
#1
Thread Starter
Hyperactive Member
I have a TextBox and I want the user to enter
a number between 0 and 6 (1 to 5). No other characters
are allowed except integer numbers between 0 and 6.
No floating point numbers or negative numbers and
no letters. Just 1, 2, 3, 4, 5.
If the user hits a key which doesn't match with
these numbers a MsgBox should appear.
Any ideas?
thx, vbzero
-
Sep 16th, 2000, 08:23 AM
#2
Frenzied Member
Code:
Text1_KeyPress(KeyAscii As Integer)
'1 = 49, 5 = 53
If KeyAscii < 49 Or KeyAscii > 53 Then
'Display Box
MsgBox "Only 1,2,3,4,5 are allowed here!"
'Stop the ASCII from getting passed to the textbox
KeyAscii = 0
End If
End Sub
Hope it helped ya!
[Edited by Jop on 09-16-2000 at 09:28 AM]
Jop - validweb.nl
Alcohol doesn't solve any problems, but then again, neither does milk.
-
Sep 16th, 2000, 08:25 AM
#3
You can use the KeyPress event:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case vbKey1 To vbKey5
'just accept
Case Else
KeyAscii = 0
MsgBox "Invalid character"
End Select
End Sub
Good luck!
-
Sep 16th, 2000, 08:33 AM
#4
Junior Member
adding this to the change event will only let the user enter in 1, 2, 3, 4 and 5s.
Code:
Private Sub Text1_Change()
If Text1.Text <> "" Then
If Asc(Mid$(Text1.Text, Len(Text1.Text), 1)) < 49 Or Asc(Mid$(Text1.Text, Len(Text1.Text), 1)) > 53 Then
Text1.Text = Mid$(Text1.Text, 1, Len(Text1.Text) - 1)
End If
End If
End Sub
-
Sep 16th, 2000, 08:41 AM
#5
Thread Starter
Hyperactive Member
Thanks! It really helped!
thx, vbzero
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
|