Frustration with Enumerations (yet again)

Exactly this. An enumeration declares a new type and it should be treated like a separate type from its underlying type.

I really do understand that, though considering enums as types who’s values are hidden but predefined, I don’t understand why we can an assign any integer value to an enum variable by casting, even if it was not part of the definition of the type.

In any case why are they limited to only integers? That same logic could apply group of strings, or colors and I can even think of cases where that concept could apply to a set of double values.

That said, what would be useful in more situations would be what I called a “Named Constant Group” - though if that existed I don’t know how much enums would get used as not having to cast would be a real convenience.

The point of requiring the use of a cast or Ctype is so you DO have to think about it and when you come back to your code in 6 months (or better to code you wrote 6 years ago) you CAN look at the code & not have to wonder what magic hidden inobvious and unstated conversions are occurring.
You have no idea how many issues I’ve fixed in the IDE over the years JUST by being explicit in code & reducing the use of variants.
It’s a lot.

This is the exact same reason why variants cause never ending issues in lots of projects we see
Some get submitted as bug reports when in fact its the unconstrained use of “hidden magic” like variants
This ranks right up there

Be explicit & be sure of whats going on
Then you don’t have to wonder about that code in a few years
Its a good coding habit

maybe it could be usefull to someone:

You can do this and it stops at the right position
(it seams to behave like an integer?)

Public Enum myEnum one=1 two=2 three=3 four=4 five=5

[code] dim myE As myEnum=myEnum.four

Select case myE
case myEnum.one to myEnum.two
Break
case myEnum.three to myEnum.five
Break
end select

if myE <myEnum.five then
Break
end if

if myE >myEnum.two then
Break
end if[/code]

I think part of the confusion comes from different programming languages background. Because standard C compilers told us that enum constants are of type int, it is hard to get that Xojo enums are of a different kind.
I remember using sets in Pascal…

[quote=341779:@Philippe Schmid]I think part of the confusion comes from different programming languages background. Because standard C compilers told us that enum constants are of type int, it is hard to get that Xojo enums are of a different kind.
I remember using sets in Pascal…[/quote]
Perhaps, but the power of enums is that the user can’t accidentally use an invalid value.