Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Verifying Enum Values

Status
Not open for further replies.

JTBorton

Technical User
Jun 9, 2008
345
DE
I'm using public enums in my class module so the user knows what values to select when sending an email. For these particular enums I want to make sure only one value is selected and that the value is in the enumeration list. Here are some of the Enums and variables I am using. When I try to test it in the property it is saying that I have an Invalid Qualifier. Does this mean I can only have [_first] = 0 and [_last] = # in one the the enums? If so then why can I make multiple custom variables that have components with the same name, but not multiple enums with components that have the same name?

Code:
Option Explicit
Option Base 1

Public Enum MsgFlagColor
    'Used to set the message flag icon color. These values correspond with the outlook values.
    [_first] = 0
    EmEng_NoFlagIcon = 0        'olNoFlagIcon
    EmEng_PurpleFlagIcon = 1    'olPurpleFlagIcon
    EmEng_OrangeFlagIcon = 2    'olOrangeFlagIcon
    EmEng_GreenFlagIcon = 3     'olGreenFlagIcon
    EmEng_YellowFlagIcon = 4    'olYellowFlagIcon
    EmEng_BlueFlagIcon = 5      'olBlueFlagIcon
    EmEng_RedFlagIcon = 6       'olRedFlagIcon
    [_last] = 6
End Enum
Public Enum MsgFlagStatus
    'Used to set the message flag status. These values correspond with the outlook values.
    [_first] = 0
    EmEng_NoFlag = 0            'olNoFlag
    EmEng_FlagComplete = 1      'olFlagComplete
    EmEng_FlagMarked = 2        'olFlagMarked
    [_last] = 2
End Enum
Public Enum MsgImportance
    'Used to set message importance.  These values correspond with the outlook values.
    [_first] = 0
    EmEng_ImportanceLow = 0     'olImportanceLow
    EmEng_ImportanceNormal = 1  'olImportanceHigh
    EmEng_ImportanceHigh = 2    'olImportanceHigh
    [_last] = 2
End Enum

Private blnHasFlag          As Boolean          'Indicates whether the message has a flag
Private intFlagColor        As MsgFlagColor     'indicates the color of the flag icon
Private intFlagStatus       As MsgFlagStatus    'Indicates the message flag status
Private dtFlagDue           As Date             'The due date of the message flag
Private strFlagRequest      As String           'A string that holds the flag request message

Complie error:
Invalid qualifier


Code:
Public Property Get Flags_FlagColor() As MsgFlagColor
    Flags_FlagColor = intFlagColor
End Property
Public Property Let Flags_FlagColor(Value As MsgFlagColor)
Dim J As Integer, blnIsValid As Boolean
    For J = [highlight]intFlagColor[/highlight].[_first] To intFlagColor.[_last]
        If Value = J Then
            blnIsValid = True
            Exit For
        End If
    Next J
    If Not blnIsValid = True Then
        Err.Raise 380 'Invalid Property Value
    End If
    
    intFlagColor = Value
    
End Property

-JTBorton
Another Day, Another Disaster
 
intFlagColor is a variable of type MsgFlagColor. It can hold a value of one of the MsgFlagColor enums but isn't a MsgFlagColor itself. Therefore the .[_first] "method" is not known to it. Substitute the actual type name (MsgFlagColor) for intFlagColor in your For..Next loop.
 
Actually, intFlagColor is a MsgFlagColor in object oriented terms, but still, substituting MsgFlagColor should still solve your problem.

Do you realize you could add a reference to "Microsoft Outlook 12.0 Object Library" and then use the built-in enumerations?
Code:
    Private intFlagColor As Outlook.OlFlagIcon
'--------
    For J = Outlook.olNoFlagIcon To Outlook.olRedFlagIcon
        '...
    Next
 
Thanks Dave. That's fixed it.

Yes, I am aware that I can link to outlook's library. Thats the whole point of what I am doing. I am trying to build a emailing class object that will handle all of your email needs for you with late binding. That way, a friend, coworker, or anyone else who gets a hold of it, could simply import the class and use it without worrying about how to send mail through outlook or worrying about reference libraries. They can simply treat it as a 'black box' and "let it do it's thing."

-JTBorton
Another Day, Another Disaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top