Results 1 to 4 of 4

Thread: numerical textbox

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    n.ireland, UK
    Posts
    157

    numerical textbox

    in something like...

    if txtBox.text = "" then
    msgbox "enter something in the textbox please"

    how would i change that if I only wanted numerical data inputted?

    thanks

  2. #2
    INXSIVE Bruce Fox's Avatar
    Join Date
    Sep 2001
    Location
    Melbourne, Australia
    Posts
    7,429
    This will also eliminate Cut n Paste problems.

    And....

    Using the Validate Event prevents the TextBox loosing focus
    before the validation is conducted (which would result in invalid
    data remaining in the TextBox.

    However, whilst a user can temporaraly enter invalid data, when
    they move to another control they are alerted, and sent
    back to the TextBox until a valid entry is made.

    VB Code:
    1. Private Sub Text1_Validate(Cancel As Boolean)
    2.     For i = 1 To Len(Text1.Text)
    3.         If Not IsNumeric(Mid(Text1.Text, i, 1)) Then
    4.             MsgBox "Invalid Charater, Numbers Only please"
    5.             Text1.SelStart = i - 1
    6.             Text1.SelLength = 1
    7.             Text1.SetFocus
    8.             Cancel = True
    9.             Exit Sub
    10.         End If
    11.     Next
    12. End Sub

  3. #3
    Former Admin/Moderator MartinLiss's Avatar
    Join Date
    Sep 1999
    Location
    San Jose, CA
    Posts
    33,431
    Here is a control that I wrote called NumberBox. It is essentially a textbox that limits input to numbers. It also has the following new properties.

    CanBeNegative
    CanHaveDecimals
    MaxDecimals
    Attached Files Attached Files

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Jan 2002
    Location
    n.ireland, UK
    Posts
    157
    thanks guys, just what i was lookin for

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