-
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
-
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.
-
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
-
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
Forum Rules
|
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
|
Bookmarks