Enumeration problem

Darc

Well-known member
Joined
Apr 18, 2003
Messages
89
ok, I have an enumeration, say:

Code:
Enum Number
    one
    two
    three
End Enum

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

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

Code:
Enum Number
    one = 1
    two = 2
End Enum

Private Sub SomeSub()
   Dim x As Number = ???
End Sub
 
Do you mean:
Code:
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 theres another method using Xor thats more effective though
 
Last edited by a moderator:
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 Im 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 dont find it possible! :D

Ill be waiting...
 
Im making a Online Card Game with MANY keywords (think MTG) And I dont 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 isnt I still dont get it... sorry...
 
No, the KEYWORDS on the cards :) Like, Creature or Building, theyre 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:
Code:
Public Structure Card
Dim firsttype As Number
Dim secondtype As Number
End Structure
 
I dont 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 youll 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