Results 1 to 4 of 4

Thread: Suggestions, please...

  1. #1

    Thread Starter
    Hyperactive Member Gimpster's Avatar
    Join Date
    Oct 1999
    Location
    Redmond, WA 98052
    Posts
    331

    Post

    Does anyone have any suggestions on how to check a textbox to make sure it contains only numbers?

    ------------------
    Ryan

    [This message has been edited by Gimpster (edited 02-14-2000).]

  2. #2
    Member
    Join Date
    Feb 2000
    Posts
    43

    Post

    there is the IsNumeric function...

    or

    If str(val(text1.text)) = str(text1.text) then [it's only numbers...] but never tested it...


    or just verify every keypress to the textbox and make sure it is a digit 0-9

    ------------------
    Rapmaster

  3. #3
    Lively Member
    Join Date
    Jul 1999
    Posts
    99

    Post

    Gimpster,

    the function "IsNumeric()" works, but recently i read about the "Like" function in a book which i found useful in my projects specially when i need string validations.

  4. #4
    Frenzied Member Buzby's Avatar
    Join Date
    Jan 1999
    Location
    UK
    Posts
    1,670

    Post

    Personally I check that it's a number on the LostFocus event - you can catch the keypresses etc in the KeyDown, Change or Keypress event but you have to allow for the copy/pasting, delete key etc etc etc.

    Textbox1_LostFocus
    If Not IsNumeric(TextBox1.Text) Then
    Msgbox "Must enter a number!"
    TextBox1.SetFocus
    End If
    End Sub

    This will prevent the user from moving onto the next control if they don't enter a number.
    If you want to allow the user to leave the textbox blank you should insert

    If TextBox1.Text="" Then Exit Sub

    immediately below the TextBox1_LostFocus line (ie, before the IF)



    ------------------
    Mark "Buzby" Beeton
    VB Developer
    [email protected]



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