LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Load the String List of an Enum programmatically

It's possible to load a the string list of an Enum programmatically, in Development mode, [But not a runtime]

I use Enum ring controls quite a bit for state machines.

The Trick:

1. On a Front panel place a "Text Ring" control.

2. Using the 'Strings' Property node of the Text ring, load your list of strings. [Typically, I do this from a delimited file]

3. Once the Text Ring has the updated list, do the following:

4. Right-click on the Text Ring and select "REPLACE", browse the Controls menu to replace it with an 'Enum Ring'.

5. The Enum ring will now have the complete list from the Text ring.

 

...A work-around I know, but the forums say this is directly impossible.

Regards

Jack

Message 1 of 13
(4,585 Views)

The impossible part is creating an enum at runtime.  What you explain is not even "programmatically".  That's using the LabVIEW UI, being able to swap controls, to your advantage.  But it does look like an easy method for populating a large list into an enum. 

 

Regarding state machines, I use the JKI State Machine, which uses strings for its state selector.  This allows you to add more than one state to the queue using multiline strings.  If you have not seen the JKI SM, I recommend that you check it out.

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 13
(4,554 Views)

Yes, you CAN do this programmatically.  You write the  array of strings to the Strings[] property of the enum.  But as you said, it can't be at "run-time".  it has to be in an enum control in a VI that is not running.

 

Message 3 of 13
(4,527 Views)

Heck, that's not programmatic!  

 

I had an application that was "driven" by an Excel Spreadsheet.  The columns (there were about 160 of them, as I recall) specified the various (named) Parameters for the test, while the rows each represented a Test (with that row's set of Parameters).  We wanted an Enum that were the Names of all the Parameters, easily populated from Row 1 of that Spreadsheet.

 

Unfortunately, the students kept dreaming up more experiments that required additional (or different) parameters, so the Spreadsheet kept changing.  With 5-10 Parameters, you'd just edit the Enum, but with >100, you want a Programmatic way to create the Enum.  That's when I learned LabVIEW Scripting.  Open Spreadsheet, read and parse Row 1, then generate the Enum, giving it a name appropriate for the Spreadsheet Name/Version.  A great Time Saver and Error Eliminator.

 

Bob Schor

0 Kudos
Message 4 of 13
(4,475 Views)

If you wired up the error cluster...you'd see LabVIEW does not allow this. What is odd is that LabVIEW should.

My post was simply a 'quick-n-dirty' way to load a enum string list, without the development distraction of setting up LabVIEW scripting, or other work-arounds.

 

image.png

 

 

0 Kudos
Message 5 of 13
(4,429 Views)

@MrJackHamilton wrote:

If you wired up the error cluster...you'd see LabVIEW does not allow this. What is odd is that LabVIEW should.


No, it should not.  You are trying to update an enum while it is in a run state.  That definitely should not be allowed.  From another VI, you can get a reference to this VI and update the enum.  That is because then the VI with the enum will be in an edit state.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 6 of 13
(4,417 Views)

The ring control should be used instead of the enum when doing this.

0 Kudos
Message 7 of 13
(4,405 Views)

@OregonGumby2 wrote:

The ring control should be used instead of the enum when doing this.


If only someone could create a thread describing how to do that 😉 


GCentral
0 Kudos
Message 8 of 13
(4,402 Views)

@cbutcher wrote:

@OregonGumby2 wrote:

The ring control should be used instead of the enum when doing this.


If only someone could create a thread describing how to do that 😉 


If only...


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 9 of 13
(4,393 Views)

Hello ,

 

Here an example of programmatically fill the elements of enum

programmatically.  for enum controls the data cannot be fille during exection , the this vi is open the cotrol from another VI and adding the data 🙂

francsicohdz_0-1723119475260.png

 

Message 10 of 13
(657 Views)