01-28-2021 12:13 PM - edited 01-28-2021 12:14 PM
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. ☺️
01-28-2021 12:33 PM
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.
01-28-2021 01:38 PM - edited 01-28-2021 01:39 PM
@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.
11-15-2022 04:28 PM - edited 11-15-2022 04:30 PM
@billko please elaborate on how to auto-populate a ring.
11-15-2022 05:04 PM
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.
11-16-2022 12:10 AM
please use the ArrayToEnum tools.
11-16-2022 09:24 AM
@ronke Where do I get the ArrayToEnum tools?
11-16-2022 09:55 AM
The key is to set the Enum strings when the .ctl is not reserved for running:
11-16-2022 10:00 AM
please refer attached toolkits.
11-16-2022 10:17 AM - edited 11-16-2022 10:23 AM
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.