LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Importing items from a text file to enum

Hello, 

I have a text file with multiple items in it. I don't want to write each and every item in the enum manually. Is there any easy or shorter way of writing/importing these items directly into an enum ?

 

Thanks in advance. ☺️

0 Kudos
Message 1 of 11
(2,197 Views)

Are you looking at defining an enum at edit-time or run-time?

 

If at run-time, you should be using a Ring.  You can set the values for a ring using a property node with the Strings[] or the Strings and Values[] property.

 

If at edit-time, then you can do something similar, but you will need to use "scripting", which would require getting a reference to the enum from another VI in order to update the values.

 

 


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 2 of 11
(2,188 Views)

@crossrulz wrote:

Are you looking at defining an enum at edit-time or run-time?

 

If at run-time, you should be using a Ring.  You can set the values for a ring using a property node with the Strings[] or the Strings and Values[] property.

 

If at edit-time, then you can do something similar, but you will need to use "scripting", which would require getting a reference to the enum from another VI in order to update the values.

 

 


I think the major roadblock is that you cannot edit strings and values of an enum while the VI is running.  But you can get around this.  You could create the enum in VI #1, create the code to auto-populate your enum in VI #2, working with a reference from the control in VI #1.  That way, VI #1 isn't really running, so you can modify the properties.  I've done it before, so it's more than just a theory.  It's not my idea - I saw it here somewhere...

 

Edit:

I forgot an easier way is to auto-populate a ring, then replace it with an enum.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
Message 3 of 11
(2,154 Views)

@billko please elaborate on how to auto-populate a ring.

0 Kudos
Message 4 of 11
(1,571 Views)

Basically you make a VI with a ring control in it and you create code to load the text into your ring via property node "Strings".  Once you've done that, you should be able to replace it with an enum.  I think there's a "fancier" way of doing it that involves a reference to an enum in a non-running VI so you can skirt the "can't modify an enum at runtime" issue, but this was easier to do.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 5 of 11
(1,555 Views)

please use the ArrayToEnum tools.

0 Kudos
Message 6 of 11
(1,540 Views)

@ronke Where do I get the ArrayToEnum tools?

0 Kudos
Message 7 of 11
(1,519 Views)

The key is to set the Enum strings when the .ctl is not reserved for running:

 

create enum.png

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 8 of 11
(1,502 Views)

please refer attached toolkits.

0 Kudos
Message 9 of 11
(1,496 Views)

Oh, arraytoenum_v11.zip from https://lavag.org/files/file/61-variant-to-control/. Or simply with a file containing each word on a line, create a new Ring and this Read from Text File to Spreadsheet To String Array code, run it, then Right-click the front panel Ring, Replace, Enum.

file-to-enum.jpg

0 Kudos
Message 10 of 11
(1,489 Views)