DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 4 of 4

Thread: Valid Integer

  1. #1
    Join Date
    Aug 2004
    Posts
    43,023

    Valid Integer

    [Originally posted by Ken Devorak]

    I want a user to be able to type out a number in a text box.ÿ How do I have Visual Basic 6.0 check there input to make sure its a valid integer or not?

    Thanks

    Ken

  2. #2
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Valid Integer

    [Originally posted by Eli Martin]

    I check the value using this function:

    Function ValidNum(KeyCode As Integer) As Boolean
    On Error GoTo Err
    'Test value to determine if it is a valid entry for a number field
    Select Case KeyCode
    ÿ ÿ Case 8 To 9
    ÿ ÿ ÿ ÿ ValidNum = True
    ÿ ÿ Case 13
    ÿ ÿ ÿ ÿ ValidNum = True
    ÿ ÿ Case 35 To 37
    ÿ ÿ ÿ ÿ ValidNum = True
    ÿ ÿ Case 39
    ÿ ÿ ÿ ÿ ValidNum = True
    ÿ ÿ Case 46
    ÿ ÿ ÿ ÿ ValidNum = True
    ÿ ÿ Case 48 To 57
    ÿ ÿ ÿ ÿ ValidNum = True
    ÿ ÿ Case 96 To 105
    ÿ ÿ ÿ ÿ ValidNum = True
    ÿ ÿ Case 144
    ÿ ÿ ÿ ÿ ValidNum = True
    ÿ ÿ Case Else
    ÿ ÿ ÿ ÿ ValidNum = False
    End Select
    ÿ ÿ
    '----------Error Handling---------------
    Exit Function
    Err:
    MsgBox Err.Number & " - " & Err.Description
    Resume Next
    End Function

    I enter this subroutine on the keyup event of the text box...This is not a perfect solution.

  3. #3
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Valid Integer

    [Originally posted by Eric]

    You can place the following code where necessary (ex: change() event)

    If NOT IsNumeric(txtNumber) Then
    ÿ msgbox("Invalid Number, please try again")
    ÿ txtNumber.SetFocus()
    ÿ Exit Sub 'stop executing
    End If

  4. #4
    Join Date
    Aug 2004
    Posts
    43,023

    Re:Re:Valid Integer

    [Originally posted by Ken Devorak]

    Thank you very much

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links