Store an Enum Value

let’s say you have an ENUM

Enum SomeEnum
Foo = 0
Bar = 1
Baz = 2

and you define a global variable to be of that type

Dim xyz as SomeEnum
xyz = SomeEnum.bar

Is there ANY way to read/write the value to a text file, where the data in the text file has some visual reference to the enum values?

I know I could read / write the value “1” , but I’d like to have something where I could look at the text file visually and know that is was “SomeEnum.Bar”
without having to create dictionaries or lookups that would defeat the entire purpose of the enum to begin with.

If not… I will use a string lteral then test for

if xyz="BAR" .....

instead of what I’d like to have

if xyz=someenum.bar ....

nope … enums have no way to take a string and map it into the value OR to take a value & map it into a string

you have to do that manually

was afraid of that.

Too bad Xojo doesn’t have a method similar to what Swift has… you can save the RawValue, and upon reading it back use that value to get the enum (assuming in the meantime you didn’t add new enum values )

guess I’ll just use a list of constant text values…

Thanks

you can write extension methods for enums so you could write a tostring and fromstring for that type

The extension technique Norman mentions is described here:

https://documentation.xojo.com/api/data_types/enumeration.html

[quote=435678:@Paul Lefebvre]The extension technique Norman mentions is described here:

https://documentation.xojo.com/api/data_types/enumeration.html[/quote]
that reroutes to
https://documentation.xojo.com/Home

works fine from the bahamas :stuck_out_tongue:

guess I’ll have to fly down there then :slight_smile:

It works Ok for me. Can you visit this page?
https://documentation.xojo.com/getting_started/using_the_xojo_language/enumerations.html

sunny and 29 with nice sandy beaches and lots of decent cold local beer
and its not outrageously expensive either (like some Caribbean islands we’ve been to)

[quote=435683:@Norman Palardy]sunny and 29 with nice sandy beaches and lots of decent cold local beer
and its not outrageously expensive either (like some Caribbean islands we’ve been to)[/quote]
29? I assume you meanCelsius? (I’m American we do Farenheit :slight_smile: or 84deg)

Thats ok… I live in Sunny Southern California… where it is that nice almost all the time… however it IS outrageously expensive

[quote=435682:@Alberto De Poo]It works Ok for me. Can you visit this page?
https://documentation.xojo.com/getting_started/using_the_xojo_language/enumerations.html[/quote]
that page does work

[quote=435686:@Dave S]29? I assume you meanCelsius? (I’m American we do Farenheit :slight_smile: or 84deg)
[/quote]
Ah yes … America … one of three countries in the world that does not use metric (Burma, Liberia, and the US)

I hate having had to buy 2 sets of wrenches to fix most things I buy from the USA. My John Deere tractor uses some metric and some imperial bolts and nuts. Drives me crazy.

@Norman Palardy — Oh don’t even get me started !! :slight_smile:

Yup… even I have to have two sets. SAE for anything done with Imperial measurements (inches), and Metric since most vehicles (motorcycles and even cars require those) at least you can sometimes swap a 3/4" SAE for a 19mm Metric :slight_smile:

cause we (americans) are smarter than the rest of the world and realize that imperial measurements are better. or we are stupider than everyone else. not sure. and yes that was sarcasm. we tried to go metric back in the late 70s or early 80s and that failed miserably. hopefully one day (before I die) we can actually switch to metric to join the rest of the world.

I don’t mind metric for nuts and bolts, but prefer imperial for construction type measurement… and am just “used” to letter/legal size paper as opposed to A and B sizes…

you arent the only one. hence why it will be a while before the change actually happens. I like imperial for construction (as that is what I grew up using) and like the papersizes of letter/legal/ledger over A*/B* too. but with all things I could get used to the new ones.

I was doing civil engineering work in the 90’s and early 00’s when most DOT’s were still letting new projects in metric, and all of the standard detail drawings had to be in metric too. Working in the CAD it was no big deal since you could flip between units, and even display dual units if you wanted.

The pain was some DOT’s (FL in particular) did not allow a direct conversion of units - in metric you had to round to the nearest 25mm. So we had to maintain two sets of standard drawings. We designed precast concrete products and there was no way were were going to invest another million $$ in new forms, so the actual pieces of concrete the DOT got were not exactly what the standard drawings said they were. They never noticed.

By around 2010 all of the DOT’s had given up on converting to metric and most of the projects that had been designed in metric had been bid and built.

I don’t think I would have had any real problems working in metric if our products had been designed to nice round metric dimensions. It’s easy to think in 5’ increments, a little more difficult to think in 1.524m increments.

Ah hahahahahahah I love when you tell jokes like this :stuck_out_tongue:

integers, I use integers for storing and retrieving enums.