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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Class Modules: Provide Users with In-Code List of Constants 1

Status
Not open for further replies.

JTBorton

Technical User
Jun 9, 2008
345
DE
I am working with a class module and some fields require specific inputs that another coder may not intuitively know. How can I create a list of acceptable conastants that will appear as a drop down when the user is coding with the custom object?

For example:
I am creating an Email Engine object that will handle all my emailing needs in code, because coding emails is such a pain. Then I can just create the blasted thing, impotr the module where needed and never have to worry about it again. Some coworkers are interested in using the module for their projects when I am finished. I want to put an option for message flags in the object, but only certain colored flags are allowed. How can I get the VBE to show a little drop down with the acceptable flag constants when another user types
[Object Variable].MessageFlag = {drop down list of options}

-JTBorton
Another Day, Another Disaster
 
I started with

Code:
Public Property Let MessageFlagColor(Value As Constants)

End Property

but that hasn't gotten me anywhere

-JTBorton
Another Day, Another Disaster
 
Use an Enum

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
PHV, thanks! I looked into it and tried the following, but it would not let me specify the property as the Enum.

Compile Error
Private Enum and user defined types cannot be used as parameters or return types for public procedures, public data members, or fields of user defined types


Code:
(Inside the Class Module)
Option Explicit
Private Enum FlagColor
    [_First] = 0
    NoFlagIcon = 0
    PurpleFlagIcon = 1
    OrangeFlagIcon = 2
    GreenFlagIcon = 3
    YellowFlagIcon = 4
    BlueFlagIcon = 5
    RedFlagIcon = 6
    [_Last] = 6
End Enum

Private intFlagColor As FlagColor

[highlight]Public Property Get Flags_FlagColor() As FlagColor[/highlight]
    Flags_FlagColor = intFlagColor
End Property

Public Property Let Flags_FlagColor(Value As FlagColor)
Dim J As Integer, blnIsValid As Boolean
    For J = intFlagColor.[_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

When I changed them back to integers but kept intFlagColor as an Enum, the intelisense wouldn't work outside of the class module.

Code:
Public Property Get Flags_FlagColor() As Integer
    Flags_FlagColor = intFlagColor
End Property

Public Property Let Flags_FlagColor(Value As Integer)
Dim J As Integer, blnIsValid As Boolean

.
. {Junk Here}
.
    
End Property

How can I set the property to display the Enum list when used outside the class module?

-JTBorton
Another Day, Another Disaster
 
Have you tried a Public Enum ?

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
Oh, well that worked. I was hoping to not have to make them public because I want to only have to import one module. Now I have to import the class module and standard module. Is there another way around it? Thanks PHV.

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

Part and Inventory Search

Sponsor

Back
Top