If you assign a value but it is invalid how to send back a flag

Posted on 2006-03-27
Last Modified: 2010-04-07
In the below code, I would only like to assign values that are greater than 0.

How do I send back a flag to say that is was not assigned to the property.
If I did this would it be a standard practice.

Public Property Let ExchangeRate(value As Double)
    If mExchangeRate <> value Then
        mExchangeRate = value
        mIsDirty = True
    End If
End Property

Question by:swansonplace
    LVL 13

    Expert Comment


    You could use a messagebox to notify the user
    LVL 85

    Accepted Solution

    Are you talking about notifying the end user or the programmer?

    If the programmer, then you can use a function instead of a property.  The function would return true/false to indicate if the value was updated or not.
    LVL 2

    Assisted Solution

    Not sure you can do it with a property, how about a function to do the same??

    Public function ExchangeRate(value As Double) as Boolean
        If mExchangeRate <> value Then
            mExchangeRate = value
            mIsDirty = True
            ExchangeRate = True
        End If
    End Property

    ExchangeRate(100) = True if the number value was changed
    False if not...
    LVL 1

    Assisted Solution

    As this is a property there are 3 solusions
    1. You can raise an error when the value is negative using RaiseError function but it will stop the program when that happends
    2. You can validate and if it is invalid force it to a predefined value.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
    Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
    Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
    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…

    737 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

    Need Help in Real-Time?

    Connect with top rated Experts

    18 Experts available now in Live!

    Get 1:1 Help Now