LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

cluster to array

I have a cluster with all U16 and U16 Enum.  When I use the cluster to array funciton, there was an error.  I believe that the error was due to the U16 enum in the cluster.  How do I fix that?

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 1 of 8
(3,098 Views)

An Enum is not an integer data type.  Thus probably the source of your error.


Paul
0 Kudos
Message 2 of 8
(3,094 Views)

 


@PJS wrote:

An Enum is not an integer data type.  Thus probably the source of your error.


Whoops... Paul, the value of an enum is passed as a integer on every wire and every node!  (it has a unique display format for the number that looks up an array of strings) 

 

 

Cluster to array requires the cluster members to all be of the same data type.  An array can only contain elements with identical properties.  So if you have a cluster of strings you can convert to an array of strings.   If you have an cluster of String, U32, DBL, Varient, Array[EXT]  you will get an error.  A cluster of {str-type-defA enum of U16,and  U16} cast to an array would require a type cast (coersion) of one element since the display properties are dissimillar on the cluster contents.


"Should be" isn't "Is" -Jay
0 Kudos
Message 3 of 8
(3,076 Views)

 

Really?  if so, using an enum of type (U32 for example) should be able to be in an cluster of other U32 elements and the cluster to array function should work  (but in actuality does not).  It is a special data type, and as you said it below, MUST be coerced to the desired data type... before a the primitive mentioned originally will work.  You can not and should not think of an enum as an integer.... If that is what you want, use a ring.  
It is closely related to being an integer, but then again... only a half step closer than a boolean datatype.  



@Jeff Bohrer wrote:

 


@PJS wrote:

An Enum is not an integer data type.  Thus probably the source of your error.


Whoops... Paul, the value of an enum is passed as a integer on every wire and every node!  (it has a unique display format for the number that looks up an array of strings) 

 

 

Cluster to array requires the cluster members to all be of the same data type.  An array can only contain elements with identical properties.  So if you have a cluster of strings you can convert to an array of strings.   If you have an cluster of String, U32, DBL, Varient, Array[EXT]  you will get an error.  A cluster of {str-type-defA enum of U16,and  U16} cast to an array would require a type cast (coersion) of one element since the display properties are dissimillar on the cluster contents.


 

 


Paul
0 Kudos
Message 4 of 8
(3,067 Views)

Others have already explained why this will not work, but I am curious why you would want to do that? At a minimum, you'll lose all associated item names of the enum. So what good is that???

 

You can convert an cluster with all U32 numeric to an array of numerics or a cluster or all identical enums (differing only in value!) to an array of such enums. If even one enum had different items, things will again break.

 

If you only want to retain the value of the enum, you can use typecast, but this seems quite useless and dangerous.

Here's an example for "all U32". But why????

 

 

 

 

 

 

0 Kudos
Message 5 of 8
(3,057 Views)

so as long as the enum is U16 like the other numeric, the type case won't become dangerous, right? 

 

I have to convert to cluster to cluster because my function requires an array.  I made the input a cluster, so that it would be more descriptive.  Not sure is that the best way or not.

 

Yik

------------------------------------------------------------------

Kudos and Accepted as Solution are welcome!
0 Kudos
Message 6 of 8
(3,044 Views)

 


@jyang72211 wrote:

so as long as the enum is U16 like the other numeric, the type case won't become dangerous, right?


 

No, it's still dangerous because typecasting such as this is a fragile process. You create a house of cards where (inevitable) programming mistakes manifest themselves as run-time errors rather than design-time compile errors.

 

One step closer to a robust system would involve a type-covert prior to the typecast (see the bottom example). The middle example is dangerous because the output is sensitive to the enum representation.

 

23654i197EBCFC9F66677C

 

Ultimately, I am skeptical of designs that rely upon the Cluster to Array prim, which often points to an underlying problem in data structure design (or the necessity to interface with a function over which you do not have control).

Message 7 of 8
(3,036 Views)

 


@PJS wrote:

 

Really?  if so, using an enum of type (U32 for example) should be able to be in an cluster of other U32 elements and the cluster to array function should work  (but in actuality does not).

 

 


The U32 and an Enum U32 have different properties.  Specifically, the Strings[] and Strings and values[] properties of the enum do not exist in a U32 so they cannot be contained in the same array since elemtnets of an array must have identical properties.

 


"Should be" isn't "Is" -Jay
0 Kudos
Message 8 of 8
(2,986 Views)