Enumeration problem

Darc

Regular
Joined
Apr 18, 2003
Messages
89
ok, I have an enumeration, say:

Visual Basic:
Enum Number
    one
    two
    three
End Enum

how can I make a variable equal one AND three at the same time?
so:

Visual Basic:
If x = Number.One And x = Number.Three
returns true?
 
no I mean the variable that's declared as a Number, how would I make it 1 and 2 at the same time?
 
I mean declaring it as the Enumeration Number!

Visual Basic:
Enum Number
    one = 1
    two = 2
End Enum

Private Sub SomeSub()
   Dim x As Number = ???
End Sub
 
Do you mean:
Visual Basic:
Dim x as Number = Number.One Or Number.Two
If (x And Number.One) = Number.One Then 'Enum contains 1 so True
Note the above only works if you use: 1,2,4,8 (^2) numbers. I think there's another method using Xor that's more effective though
 
Last edited:
re: AndreRyan

If you specify the FlagsAttribute attribute on the Enum and leave out the enum id for each element, it will do the expontential numbering for you.

As far as I'm aware, the And method is the best way to do it.
 
I think nobody understood your problem... neither did I! :)

So, explain it better... I would recomend that you start explaining why would you ever want to have one single valriable, ha 2 values of an ENUM at the same time... Maybe we find you another way aroung cause I don't find it possible! :D

I'll be waiting...
 
I'm making a Online Card Game with MANY keywords (think MTG) And I don't want to make literally 50 boolean properties and arguments per function...
 
Let me see if I got it...
The ENUM have all the cards and you wnat to have a variable to handle all the cards of each player?
Is that it?

If it isn't I still don't get it... sorry...
 
No, the KEYWORDS on the cards :) Like, Creature or Building, they're just status of the card so I need to have more than one on a card (like "Strong" and "Creature")
 
I think im somehow beginning to understand you :).
If they have different values then it wouldnt make sense that one variable could have two different ones. What about making a structure or a class that will hold two variables of that enumeration type and you assign the enumaration values to them. Something like this:
Visual Basic:
Public Structure Card
Dim firsttype As Number
Dim secondtype As Number
End Structure
 
I don't know if those keywords have a fixed max value or not...
If so, the mutants idea is perfect, You put the structure on the array of cards and there you go ... If not you'll have to use a second array. Each item on the array of cards have an array in it with all the keywords of each card...

Solved ?? :D
 
Back
Top