CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 3 of 3
  1. #1
    Join Date
    Apr 2001
    Posts
    3

    Restrict input of a textbox to numbers

    I wanna make a textbox only accept number input,what shall I do?

    Source code may make me easier :P


  2. #2
    Join Date
    Apr 2001
    Posts
    9

    Re: Restrict input of a textbox to numbers

    Hi,
    you could use this code:

    private Sub Text1_KeyPress(KeyAscii as Integer)
    Select Case KeyAscii
    Case Asc("0") to Asc("9")
    Case else:
    KeyAscii = 0
    End Select
    End Sub




    Bye,
    O.K


  3. #3
    Join Date
    Jun 2000
    Posts
    104

    Re: Restrict input of a textbox to numbers


    private Sub Text1_KeyPress(KeyAscii as Integer)
    if keyAscii=8 then exit sub
    if not isNumeric(chr(KeyAscii)) then
    KeyAscii=0
    end if
    End Sub



    the ascii value of BackSpace is 8.
    isnumeric is a function used to check whether the value is numeric or not.





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

Featured