Results 1 to 6 of 6

Thread: begginner

  1. #1

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    I have a text box that the user must enter a number into; How do I format the text box to only accept numbers?

    Thanks,

    JO

  2. #2
    The Devil crptcblade's Avatar
    Join Date
    Aug 2000
    Location
    Quetzalshacatenango
    Posts
    9,091
    check out this thread, maybe it will help:

    http://forums.vb-world.net/showthrea...threadid=29729

  3. #3

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    Thanks-a-gig

    That did it!

    JO

  4. #4
    Guest
    Even easier:

    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
        If IsNumeric(Chr(KeyAscii)) <> True Then KeyAscii = 0
    End Sub

  5. #5
    Frenzied Member Jop's Avatar
    Join Date
    Mar 2000
    Location
    Amsterdam, the Netherlands
    Posts
    1,986
    Matthew, that'll not work if the user backspaces, spaces or use the arrow buttons.
    Use this instead:
    Code:
    Private Sub Text1_KeyPress(KeyAscii As Integer)
    '1 to 32 are system keys (del, space, tab, ctrl + V/C/Z, etc.)
    If KeyAscii < 33 Then Exit Sub
    If Not (IsNumeric(Chr(KeyAscii))) Then KeyAscii = 0
    End Sub
    It's pretty easy too!
    Jop - validweb.nl

    Alcohol doesn't solve any problems, but then again, neither does milk.

  6. #6

    Thread Starter
    Fanatic Member joltremari's Avatar
    Join Date
    Sep 2000
    Location
    Mississippi
    Posts
    674
    Thanks!!!!!

    JO

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