Discussion:
Unique integers?
Jim Wagner
2016-07-28 22:20:34 UTC
Permalink
Greetings -

Don't quite know how to title this. A while back, someone gave me a great example of generating a unique list of named constants (like an ENUM) and a variable with the same type. I would now like to use that to create a significant list of named unique state constants and a variable that will only accept those constants.

Looked up in the LR and it gave me NO hints, what so ever. ENUMs seemed to be reserved for specific applications and seemed to be all predefined.

What can I do? Hints and outright solutions are all gratefully appreciated.

Many thanks
Jim

James Wagner
Oregon Research Electronics

_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
vaughnsc .
2016-07-28 22:31:46 UTC
Permalink
Sounds like Enums to me. I don't think their application is 'limited', why?

Dim myState as stateEnum
MyState=stateEnum.stateName

Assigning anything other than a stateEnum throws an exception.
Enums can be 'natural order' or assigned.
On Jul 28, 2016 6:23 PM, "Jim Wagner" <***@comcast.net> wrote:

Greetings -

Don't quite know how to title this. A while back, someone gave me a great
example of generating a unique list of named constants (like an ENUM) and a
variable with the same type. I would now like to use that to create a
significant list of named unique state constants and a variable that will
only accept those constants.

Looked up in the LR and it gave me NO hints, what so ever. ENUMs seemed to
be reserved for specific applications and seemed to be all predefined.

What can I do? Hints and outright solutions are all gratefully appreciated.

Many thanks
Jim

James Wagner
Oregon Research Electronics

_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
vaughnsc .
2016-07-29 03:20:50 UTC
Permalink
For sake of completeness: you add an Enum the same way you add properties
or methods to a class or module. Then you see the Editor (named values) and
Inspector (Type Name).

As noted before the default values count up from zero by order added, but
you are free to assign any signed integer value individually.

Hope this gets you going.
Post by vaughnsc .
Sounds like Enums to me. I don't think their application is 'limited', why?
Dim myState as stateEnum
MyState=stateEnum.stateName
Assigning anything other than a stateEnum throws an exception.
Enums can be 'natural order' or assigned.
Greetings -
Don't quite know how to title this. A while back, someone gave me a great
example of generating a unique list of named constants (like an ENUM) and a
variable with the same type. I would now like to use that to create a
significant list of named unique state constants and a variable that will
only accept those constants.
Looked up in the LR and it gave me NO hints, what so ever. ENUMs seemed to
be reserved for specific applications and seemed to be all predefined.
What can I do? Hints and outright solutions are all gratefully appreciated.
Many thanks
Jim
James Wagner
Oregon Research Electronics
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
Jim Wagner
2016-07-29 05:48:01 UTC
Permalink
Thanks for closing the circle, Vaughn. Appreciate that!

Jim

James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by vaughnsc .
For sake of completeness: you add an Enum the same way you add properties
or methods to a class or module. Then you see the Editor (named values) and
Inspector (Type Name).
As noted before the default values count up from zero by order added, but
you are free to assign any signed integer value individually.
Hope this gets you going.
Post by vaughnsc .
Sounds like Enums to me. I don't think their application is 'limited', why?
Dim myState as stateEnum
MyState=stateEnum.stateName
Assigning anything other than a stateEnum throws an exception.
Enums can be 'natural order' or assigned.
Greetings -
Don't quite know how to title this. A while back, someone gave me a great
example of generating a unique list of named constants (like an ENUM) and a
variable with the same type. I would now like to use that to create a
significant list of named unique state constants and a variable that will
only accept those constants.
Looked up in the LR and it gave me NO hints, what so ever. ENUMs seemed to
be reserved for specific applications and seemed to be all predefined.
What can I do? Hints and outright solutions are all gratefully appreciated.
Many thanks
Jim
James Wagner
Oregon Research Electronics
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
Jon Ogden
2016-08-01 18:31:40 UTC
Permalink
There’s actually an enum page on the online docs site:

http://developer.xojo.com/enumeration

Paul is going to be making sure it gets added to the offline docs as well.

Jon
Post by Jim Wagner
Thanks for closing the circle, Vaughn. Appreciate that!
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by vaughnsc .
For sake of completeness: you add an Enum the same way you add properties
or methods to a class or module. Then you see the Editor (named values) and
Inspector (Type Name).
As noted before the default values count up from zero by order added, but
you are free to assign any signed integer value individually.
Hope this gets you going.
Post by vaughnsc .
Sounds like Enums to me. I don't think their application is 'limited', why?
Dim myState as stateEnum
MyState=stateEnum.stateName
Assigning anything other than a stateEnum throws an exception.
Enums can be 'natural order' or assigned.
Greetings -
Don't quite know how to title this. A while back, someone gave me a great
example of generating a unique list of named constants (like an ENUM) and a
variable with the same type. I would now like to use that to create a
significant list of named unique state constants and a variable that will
only accept those constants.
Looked up in the LR and it gave me NO hints, what so ever. ENUMs seemed to
be reserved for specific applications and seemed to be all predefined.
What can I do? Hints and outright solutions are all gratefully appreciated.
Many thanks
Jim
James Wagner
Oregon Research Electronics
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xo
Jim Wagner
2016-08-01 19:08:19 UTC
Permalink
Hello, Jon -

I am now having difficulty using my Enum (which denotes states in a Finite State Machine) in a Select Case statement. It says that it expects an integer but got an enum. Certainly, select will work with an enum since it works with other non-integer arguments (e.g. strings). If I need to cast the argument as an integer, then what happens in the various case statements? The compiler does not seem to complain about "case TabState.ePost".

Many thanks
Jim Wagner
Oregon Research Electronics

----- Original Message -----

From: "Jon Ogden" <***@mac.com>
To: "Nug" <***@lists.xojo.com>
Sent: Monday, August 1, 2016 11:31:40 AM
Subject: Re: Unique integers?

There’s actually an enum page on the online docs site:

http://developer.xojo.com/enumeration

Paul is going to be making sure it gets added to the offline docs as well.

Jon

_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xo
Jon Ogden
2016-08-01 19:35:16 UTC
Permalink
Jim,

OK. I just verified this by writing some quick code myself.

So when using an enum you have two parts to it.

1.) First you create the enum itself which effectively creates the new type.
2.) You create a property of the type of the enum you created in step 1.

So let’s say you created an enum called MyEnum. It has three values: State1, State2, State3. Let’s say the property you are using is named TheEnum and it’s of type MyEnum.

Now, in the select case statement you would use:

Select Case TheEnum

Case MyEnum.State1
//Code

Case MyEnum.State2
// Code

Case MyEnum.State3
// Code

End Select


This does work. What I bet you are doing is this:

Select Case TheEnum

Case TheEnum.State1

Case TheEnum.State2

Case TheEnum.State3

End Select


That will throw an error.

Jon
Post by Jim Wagner
Hello, Jon -
I am now having difficulty using my Enum (which denotes states in a Finite State Machine) in a Select Case statement. It says that it expects an integer but got an enum. Certainly, select will work with an enum since it works with other non-integer arguments (e.g. strings). If I need to cast the argument as an integer, then what happens in the various case statements? The compiler does not seem to complain about "case TabState.ePost".
Many thanks
Jim Wagner
Oregon Research Electronics
----- Original Message -----
Sent: Monday, August 1, 2016 11:31:40 AM
Subject: Re: Unique integers?
http://developer.xojo.com/enumeration
Paul is going to be making sure it gets added to the offline docs as well.
Jon
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <listh
Jim Wagner
2016-08-01 19:49:12 UTC
Permalink
Jon -

The problem was that the case statements still contained constants from the pre-enum implementation. What threw me was that the error was indicated in the select case line, not in the case lines. I would expect the select case statement to define the data type to which the case statements have to conform, not the other way around.

Anyway, it works now. Appreciate your help!

Jim

----- Original Message -----

From: "Jon Ogden" <***@mac.com>
To: "Nug" <***@lists.xojo.com>
Sent: Monday, August 1, 2016 12:35:16 PM
Subject: Re: Unique integers?

Jim,

OK. I just verified this by writing some quick code myself.

So when using an enum you have two parts to it.

1.) First you create the enum itself which effectively creates the new type.
2.) You create a property of the type of the enum you created in step 1.

So let’s say you created an enum called MyEnum. It has three values: State1, State2, State3. Let’s say the property you are using is named TheEnum and it’s of type MyEnum.

Now, in the select case statement you would use:

Select Case TheEnum

Case MyEnum.State1
//Code

Case MyEnum.State2
// Code

Case MyEnum.State3
// Code

End Select


This does work. What I bet you are doing is this:

Select Case TheEnum

Case TheEnum.State1

Case TheEnum.State2

Case TheEnum.State3

End Select


That will throw an error.

Jon
Post by Jim Wagner
Hello, Jon -
I am now having difficulty using my Enum (which denotes states in a Finite State Machine) in a Select Case statement. It says that it expects an integer but got an enum. Certainly, select will work with an enum since it works with other non-integer arguments (e.g. strings). If I need to cast the argument as an integer, then what happens in the various case statements? The compiler does not seem to complain about "case TabState.ePost".
Many thanks
Jim Wagner
Oregon Research Electronics
----- Original Message -----
Sent: Monday, August 1, 2016 11:31:40 AM
Subject: Re: Unique integers?
http://developer.xojo.com/enumeration
Paul is going to be making sure it gets added to the offline docs as well.
Jon
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>

_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

Jon Ogden
2016-07-29 01:26:57 UTC
Permalink
An enum is a new type. Use them however you want. Very useful. Not limited at all.

Sent from my iPhone
Post by Jim Wagner
Greetings -
Don't quite know how to title this. A while back, someone gave me a great example of generating a unique list of named constants (like an ENUM) and a variable with the same type. I would now like to use that to create a significant list of named unique state constants and a variable that will only accept those constants.
Looked up in the LR and it gave me NO hints, what so ever. ENUMs seemed to be reserved for specific applications and seemed to be all predefined.
What can I do? Hints and outright solutions are all gratefully appreciated.
Many thanks
Jim
James Wagner
Oregon Research Electronics
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.com>
Jim Wagner
2016-07-29 01:39:30 UTC
Permalink
Thanks! I looked up “ENUM” in the LR, and all I got were things like iEnumVariant and stuff like FontUnits Enumeration.

I could not find anything that looked like it was a description of the basic language capability for general enum. This was by clicking the Help icon at the top of the IDE, then entered Enum in the search field. Also found nothing when I opened “Enumeration” in the LR list at the left edge of the LR window.

Jim

James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by Jon Ogden
An enum is a new type. Use them however you want. Very useful. Not limited at all.
Sent from my iPhone
Post by Jim Wagner
Greetings -
Don't quite know how to title this. A while back, someone gave me a great example of generating a unique list of named constants (like an ENUM) and a variable with the same type. I would now like to use that to create a significant list of named unique state constants and a variable that will only accept those constants.
Looked up in the LR and it gave me NO hints, what so ever. ENUMs seemed to be reserved for specific applications and seemed to be all predefined.
What can I do? Hints and outright solutions are all gratefully appreciated.
Many thanks
Jim
James Wagner
Oregon Research Electronics
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.com>

List Help: <***@xojo.
Jon Ogden
2016-07-29 02:01:43 UTC
Permalink
This looks to be a language reference bug. I just went to the CheckedStates Enumeration help page and it has a link to “Enumerations” at the bottom of the window and clicking that link does nothing.
Post by Jim Wagner
Thanks! I looked up “ENUM” in the LR, and all I got were things like iEnumVariant and stuff like FontUnits Enumeration.
I could not find anything that looked like it was a description of the basic language capability for general enum. This was by clicking the Help icon at the top of the IDE, then entered Enum in the search field. Also found nothing when I opened “Enumeration” in the LR list at the left edge of the LR window.
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by Jon Ogden
An enum is a new type. Use them however you want. Very useful. Not limited at all.
Sent from my iPhone
Post by Jim Wagner
Greetings -
Don't quite know how to title this. A while back, someone gave me a great example of generating a unique list of named constants (like an ENUM) and a variable with the same type. I would now like to use that to create a significant list of named unique state constants and a variable that will only accept those constants.
Looked up in the LR and it gave me NO hints, what so ever. ENUMs seemed to be reserved for specific applications and seemed to be all predefined.
What can I do? Hints and outright solutions are all gratefully appreciated.
Many thanks
Jim
James Wagner
Oregon Research Electronics
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-leave
Jon Ogden
2016-07-29 02:04:49 UTC
Permalink
<feedback://showreport?report_id=44766>
Post by Jon Ogden
This looks to be a language reference bug. I just went to the CheckedStates Enumeration help page and it has a link to “Enumerations” at the bottom of the window and clicking that link does nothing.
Post by Jim Wagner
Thanks! I looked up “ENUM” in the LR, and all I got were things like iEnumVariant and stuff like FontUnits Enumeration.
I could not find anything that looked like it was a description of the basic language capability for general enum. This was by clicking the Help icon at the top of the IDE, then entered Enum in the search field. Also found nothing when I opened “Enumeration” in the LR list at the left edge of the LR window.
Jim
James Wagner
Oregon Research Electronics
https://sites.google.com/site/oregonresearchelectronics/home
Post by Jon Ogden
An enum is a new type. Use them however you want. Very useful. Not limited at all.
Sent from my iPhone
Post by Jim Wagner
Greetings -
Don't quite know how to title this. A while back, someone gave me a great example of generating a unique list of named constants (like an ENUM) and a variable with the same type. I would now like to use that to create a significant list of named unique state constants and a variable that will only accept those constants.
Looked up in the LR and it gave me NO hints, what so ever. ENUMs seemed to be reserved for specific applications and seemed to be all predefined.
What can I do? Hints and outright solutions are all gratefully appreciated.
Many thanks
Jim
James Wagner
Oregon Research Electronics
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
_______________________________________________
Unsubscribe by sending a message to:
<nug-***@lists.xojo.c
Continue reading on narkive:
Loading...