We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

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

swansonplace
swansonplace asked
on
Medium Priority
218 Views
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

Comment
Watch Question


You could use a messagebox to notify the user
High School Computer Science, Computer Applications, Digital Design, and Mathematics Teacher
CERTIFIED EXPERT
Top Expert 2009
Commented:
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.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts
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...
Hi
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.

Luck
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.