LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Large Enum list

Solved!
Go to solution

I have an enum that originally had about 30 items from which to select.  Not too bad.  The customer recently asked if we could add (seriously) over 700 entries to this same enum!  These strings are all available in a text file, and are sequential (numeric value of each enum) in nature.  Is there any way to read in, import, all of these values into the enum?  Right now, my only option is to copy/paste each one manually.

0 Kudos
Message 1 of 13
(5,926 Views)
Solution
Accepted by topic author mrbean

@mrbean wrote:

I have an enum that originally had about 30 items from which to select.  Not too bad.  The customer recently asked if we could add (seriously) over 700 entries to this same enum!  These strings are all available in a text file, and are sequential (numeric value of each enum) in nature.  Is there any way to read in, import, all of these values into the enum?  Right now, my only option is to copy/paste each one manually.


It's a bit tricky.  First, make a ring control.  Use the text file to load those strings into the "strings" property node of the ring control.  Replace the ring with an enum.  There you go.

 

You can't (easily) do this with an enum, since enums strings can't be modified at runtime; however, if you have the enum control in a different VI and have a reference to it, you can update the property that way... but starting with a ring and replacing it is a lot easier.

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 2 of 13
(5,924 Views)

Well, with some LabVIEW scripting you probably can create an enum control with all those items…

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 3 of 13
(5,888 Views)

@GerdW wrote:

Well, with some LabVIEW scripting you probably can create an enum control with all those items…


You could, but as with anything if you want to edit a control, scripting or not, it can not be part of any running VI hierarchy. But then using directly the VI property "Strings[]" works too. Sure it could be considered scripting to use that property but technically it's part of the standard properties that are even available without the scripting extension being enabled.

 

But in the past I always used the import into Ring control method with changing it to a Enum afterwards.

Rolf Kalbermatter
My Blog
0 Kudos
Message 4 of 13
(5,882 Views)

Actually, I did use scripting to create an Enum.  I was working on a data acquisition/control project that was driven by an Excel Worksheet that had (I'm guessing) about 150 row or column headers that became associated with the variable saved in that row/column.  For example, one column was called "Trial Index", and when the Excel sheet was read, the data were put into an array indexed by the Enum.  So if I wanted the "Trial Index", I just used the Enum as the index into the Array and got out the value (there's more to it than that, but that's the idea).

 

Data Structures are never "static", as we keep dreaming up new things to do, which we accomodate by "adding a few rows/column to the WorkSheet".  Grumble, this means a new Version of the Code, with a new building of the Enum.  I wrote a stand-alone program to do this -- it parses Excel, figures out all the Excel names I need, then using Scripting, builds an Enum with the names written into the Strings[] property.  It seems to work ...

 

Bob Schor

 

I'm going to try to attach this as a Snippet.  There are some sub-VIs that do "obvious things", but most of the code should be evident ...

Create Excel Names.png

I should mention that I've run this using LabVIEW 2012 and 2014 -- I'm hoping to migrate (and restructure) the code with LabVIEW 2016, but it hasn't happened yet.

Message 5 of 13
(5,842 Views)

Although I was able to bring in the file contents into a ring, then convert to enum, I now have a different problem.  The typedef I'm creating now complains that "Enumeration items must be unique".  To ensure that I didn't have any unique items, I wrote some code to test the input file.  These entries are about 72 characters long, where only the last few differ in each, thus making them unique.  And, there are 754 enums.  Is there a MAX length on an individual entry?  If so, then they're all getting truncated after ? characters and the type thinks all the entries are the same.  Related, is there a max number of entries or max total number of characters?

0 Kudos
Message 6 of 13
(5,798 Views)

I created a sample enum that each item was 240 characters long with only the last character being different.  It did not give me a problem.

Icreated a sample enum, as soon as I went greter than 255 characters long, that is when it gold me there was a problem.

 

It seems like there could be a limit, but I haven't hit it yet.

 255 seems to be the limit.

 

And interestingly enough, the tool tip that shows up when you hover over the enum is only able to show 253 of the characters.

 

Attached is a VI if you want to play.

 

Are you 100% sure you don't have a duplicate in there?

0 Kudos
Message 7 of 13
(5,793 Views)

Can you possibly save that to labview 9.0.1, as that is what I am using.  I'm wondering if it's a max TOTAL number of characters issue, as I have 754 entries

0 Kudos
Message 8 of 13
(5,786 Views)

@RavensFan wrote:

I created a sample enum that each item was 240 characters long with only the last character being different.  It did not give me a problem.

Icreated a sample enum, as soon as I went greter than 255 characters long, that is when it gold me there was a problem.

 

It seems like there could be a limit, but I haven't hit it yet.

 255 seems to be the limit.

 


That's per item name and that is because each item name is stored as a Pascal string. Pascal strings contain a single byte in the beginning that specifies the number of characters to follow and as such this can be maximally 255. Many things in LabVIEW are internally stored as Pascal strings such as the individual level elements of a path. There is another potential limit that all element names together can't be larger than 65535 bytes including the individual length bytes as that would overflow the internal typedescriptor of an enum.

 

In older LabVIEW versions that limit applied to the complete typedescriptor, which is why super-mega-prontosaurous clusters could turn LabVIEW into a mess, but that was changed in LabVIEW 8.0 by deprecating the old 16 bit typedescriptor format and instead using a new one that the Flatten to Variant returns. The Flatten to String by default lost the typedescriptor output that used to be the 16 bit typedescriptor. 

Rolf Kalbermatter
My Blog
Message 9 of 13
(5,776 Views)

@rolfk wrote:

@RavensFan wrote:

I created a sample enum that each item was 240 characters long with only the last character being different.  It did not give me a problem.

Icreated a sample enum, as soon as I went greter than 255 characters long, that is when it gold me there was a problem.

 

It seems like there could be a limit, but I haven't hit it yet.

 255 seems to be the limit.

 


That's per item name and that is because each item name is stored as a Pascal string. Pascal strings contain a single byte in the beginning that specifies the number of characters to follow and as such this can be maximally 255. Many things in LabVIEW are internally stored as Pascal strings such as the individual level elements of a path. There is another potential limit that all element names together can't be larger than 65535 bytes including the individual length bytes as that would overflow the internal typedescriptor of an enum.

 

In older LabVIEW versions that limit applied to the complete typedescriptor, which is why super-mega-prontosaurous clusters could turn LabVIEW into a mess, but that was changed in LabVIEW 8.0 by deprecating the old 16 bit typedescriptor format and instead using a new one that the Flatten to Variant returns. The Flatten to String by default lost the typedescriptor output that used to be the 16 bit typedescriptor. 


I love this forum.  🙂

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 10 of 13
(5,761 Views)