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

Mutually Exclusive Enums 2

Status
Not open for further replies.

williamu

Programmer
Apr 8, 2002
494
GB
Hi,

I'm creating a class that contains several enumerations. However, some of these are mutually exclusive and since VB doesn't support a (C/C++ type) Union does any one know of a way I can do this?

Thanks,

William
Software Engineer
ICQ No. 56047340
 
Given that members of a VB enumeration can only be longs, I suspect you might find more limitations than exclusivity. Plus, I have to admit that I'm not quite sure where an exclusive VB enum would be useful
 
Hi strongm,

Well the idea behind it was more a case of ease of use, since the enum value names would be different in enum A than they were in enum B and that A might be longer than B or vice-versa. It's no big deal I just thought I'd ask.

However, what limitations are you refering to?


William
Software Engineer
ICQ No. 56047340
 
Oh...

For example, one of the things about VB (when you switch Option Explixit on) is that it is a strongly-typed language. I happen to be a fan of that, and like the fact that parameters get checked when I pass them to functions and procedures.

Sadly, this parameter checking gets turned off if you specify an Enum as the parameter. In fact, the procedure of function no longer cares what you pass it (except whether it can be coerced into a long) . Does not even have to be the specified enum...

Indeed, there is no easy way in VB to tell whether a value is in a specific Enum.

Code:
Option Explicit

Private Enum AnEnumDemo
    First = 1
    Second = 2
    third
    fourth = 3
End Enum

Private Enum DifferentEnum
    Eighth = 8
End Enum


Private Sub Command1_Click()
    DoSomethingWithEnum third
    DoSomethingWithEnum Eighth
    DoSomethingWithEnum "11"
    DoSomethingWithEnum 3.14
End Sub


Private Sub DoSomethingWithEnum(myEnum As AnEnumDemo)
    Debug.Print myEnum
End Sub
 
I didn't know that, and very interesting, so that's something else I've learned today. Thanks.

--
William
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top