Results 1 to 6 of 6

Thread: how to validate the input in my text box

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Philippines
    Posts
    49

    Question

    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?

  2. #2
    Fanatic Member ExcalibursZone's Avatar
    Join Date
    Feb 2000
    Location
    Western NY State
    Posts
    908
    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
    -Excalibur

  3. #3
    Lively Member
    Join Date
    Jan 1999
    Location
    Burlington, IA, USA`
    Posts
    77

    Talking

    '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

  4. #4

    Thread Starter
    Member
    Join Date
    Oct 2000
    Location
    Philippines
    Posts
    49
    thanks.

    but what is the equivalent char of asc value 8?

  5. #5
    Guest
    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.

  6. #6
    Guest
    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
  •  



Click Here to Expand Forum to Full Width