LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Convert an Array of Variants of Enums to an Array of Enums

Solved!
Go to solution

 

I have a piece of data that is a 1D array where the array element is a variant of an enum.

 

How do I convert this to an array where the array element is the enum, not a variant?

 

The only access I have to the enum properties are through the variant of the enum.
I can't just drop a constant on the block diagram and wire it to the Variant to Data VI.
Getting just the numeric values, or converting them to the string values is not enough.
I need the data type of the array element to match the original enum.

 

Thanks

0 Kudos
Message 1 of 13
(3,041 Views)

AFAIK, enums are defined at edit-time, not compile time, so you can't "make a new enum" on-the-fly like you're trying to do. You can probably make a ring though. Would that work? What exactly are you trying to achieve?

0 Kudos
Message 2 of 13
(3,036 Views)

This is the "safe" way to do it.  I don't know if you can directly convert an array of variants into an array of enums.

Capture.PNG

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 3 of 13
(2,985 Views)

@BrittonB wrote:

 

The only access I have to the enum properties are through the variant of the enum.
I can't just drop a constant on the block diagram and wire it to the Variant to Data VI.
Getting just the numeric values, or converting them to the string values is not enough.
I need the data type of the array element to match the original enum.


 

 

I suppose, you are looking for the now deprecated 

"..National Instruments\LabVIEW 2019\vi.lib\Utility\GetTyp.llb"

 

this .llb can be used like shown in the following example from this source

"GetTypeInfo.vi"and  "GetNumericInfo.vi" can be replaced by the counterpart of the Data Type Parsing VIs

 

2019_enum_to_value.png

 

0 Kudos
Message 4 of 13
(2,980 Views)

@alexderjuengere wrote:

@BrittonB wrote:

 

The only access I have to the enum properties are through the variant of the enum.
I can't just drop a constant on the block diagram and wire it to the Variant to Data VI.
Getting just the numeric values, or converting them to the string values is not enough.
I need the data type of the array element to match the original enum.


 

 

I suppose, you are looking for the now deprecated 

"..National Instruments\LabVIEW 2019\vi.lib\Utility\GetTyp.llb"

 

this .llb can be used like shown in the following example from this source

"GetTypeInfo.vi"and  "GetNumericInfo.vi" can be replaced by the counterpart of the Data Type Parsing VIs

 

2019_enum_to_value.png

 


I don't think they are deprecated.  They are there in LV 2020.  I guess I missed the intent of the original post, though?

 

Edit: Maybe those are old versions of the VIs?  There are current VIs with the same name but different icons where you expect them in the palette.

 

You know, I should just read more carefully.

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 13
(2,955 Views)

@billko wrote:

 


I don't think they are deprecated.  They are there in LV 2020.  I guess I missed the intent of the original post, though?

 

Edit: Maybe those are old versions of the VIs?  There are current VIs with the same name but different icons where you expect them in the palette.


Deprecated doesn't mean they no longer exist or can't be used.  It means NI no longer desires for them to be used.  That  they might be superceded by a newer version.  And there is a risk that at some point in the future they will disappear.

 

The red X on the icon indicates this status.

0 Kudos
Message 6 of 13
(2,943 Views)

@RavensFan wrote:

@billko wrote:

 


I don't think they are deprecated.  They are there in LV 2020.  I guess I missed the intent of the original post, though?

 

Edit: Maybe those are old versions of the VIs?  There are current VIs with the same name but different icons where you expect them in the palette.


Deprecated doesn't mean they no longer exist or can't be used.  It means NI no longer desires for them to be used.  That  they might be superceded by a newer version.  And there is a risk that at some point in the future they will disappear.

 

The red X on the icon indicates this status.


We crossed posts.  They are deprecated and replaced by new Vis with the same name, just as he showed - and said.  And as you said, also.  Which means I didn't read his post correctly.

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

Here is a better explanation of my issue.  

The VI requires the OpenG Toolkit to run.  It is written in LV2018.  

 

BrittonB_0-1592841525316.png

 

0 Kudos
Message 8 of 13
(2,855 Views)

@BertMcMahan wrote:

AFAIK, enums are defined at edit-time, not compile time, so you can't "make a new enum" on-the-fly like you're trying to do. You can probably make a ring though. Would that work? What exactly are you trying to achieve?


 

I don't need to define a new enum.  I need to set new values in an array of existing enums.  

I use a ring control for the user interface, but I need to convert the user input back into the correct enum data type.  

I added a VI to this discussion to demonstrate my issue.  

 

Thanks

0 Kudos
Message 9 of 13
(2,853 Views)

@billko wrote:

This is the "safe" way to do it.  I don't know if you can directly convert an array of variants into an array of enums.

Capture.PNG


This is definitely the most straight forward way to fix the issue.  

But it would mean that I need to maintain a case structure of all the enums that could possibly fill the array.  

Enums are added and subtracted all the time.  I do not want to maintain that case structure.  

All the data type information I need is carried with the variant, I just don't know how to build the object correctly.  

I added a VI to this discussion thread to illustrate my issue more clearly.  

 

Thanks

0 Kudos
Message 10 of 13
(2,849 Views)