|
-
Oct 4th, 2000, 09:42 PM
#1
Thread Starter
Member
i want that my text box accepts only numeric values. How do i do that? is there a "not in(0..9)" syntax, just like in Pascal?
-
Oct 4th, 2000, 09:55 PM
#2
Fanatic Member
Here ya go:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If KeyAscii < 48 Or KeyAscii > 57 Then
If KeyAscii <> 8 Then KeyAscii = 0
End If
End Sub
-
Oct 4th, 2000, 10:00 PM
#3
Lively Member
'Numerics only please!
Private Sub Text1_KeyPress(KeyAscii As Integer)
Select Case KeyAscii
Case Asc("0") To Asc("9")
Case Else
KeyAscii = 0
End Select
End Sub
An ass may bray a good long time before he shakes the stars down.
T.S. Elliot
-
Oct 4th, 2000, 10:03 PM
#4
Thread Starter
Member
thanks.
but what is the equivalent char of asc value 8?
-
Oct 4th, 2000, 10:11 PM
#5
You should add:
Code:
Private Sub Text1_KeyPress(KeyAscii As Integer)
If IsNumeric(Chr(KeyAscii)) Then Exit Sub
KeyAscii = 0
Beep
End Sub
Private Sub Text1_Change()
Dim i As Integer, s As String, t As String
For i = 1 to Len(Text1)
s = Mid(Text1, i, 1)
If Not IsNumeric(s) Then s = ""
t = t & s
Next
Text1.Text = t
End Sub
You earn 1 face as a token.
-
Oct 4th, 2000, 10:13 PM
#6
The Equal of Chr 8 is <-Backspace.
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
|