Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Error handle

Posted on 1999-07-04
2
Medium Priority
?
178 Views
Last Modified: 2010-05-02
Since there are more than three Textboxes in my application needed the user input number from 0
to 9999, I want a function which could deal with
the input errors, and give me an example to tell
how to call the function. Thanks!
0
Comment
Question by:leeann
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 

Accepted Solution

by:
marscpa earned 200 total points
ID: 1521837
This is how I would write a quick function:

Private Function ValInput(sInput As String) As Boolean
    If IsNumeric(sInput) = True Then
        If Val(sInput) >= 0 And Val(sInput) < 10000 Then
            ValInput = True
        Else
            ValInput = False
        End If
    Else
        ValInput = False
    End If
End Function

This example doesn't let the user leave the text box if the input doesn't pass validation. I'd probably add a msg box.

Private Sub Text1_LostFocus()
    If ValInput(Text1.Text) = False Then
        Text1.SetFocus
        Text1.SelStart = 0
        Text1.SelLength = Len(Text1.Text)
    End If
End Sub

The IF statement here demonstrates calling the function.


0
 

Expert Comment

by:mirrorinternetzahavnet
ID: 1521838
I would do it even shorter:

Private Function ValInput(sInput As String) As Boolean

If Not IsNumeric(sInput) = True Then exit function
If Val(sInput) < 0 And _
                 Val(sInput) > 10000 Then Exit Function
 
ValInput = True
End Function


0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

715 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question