Valid Integer


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

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

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


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center