LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Populate automatically an array of different element types

Hi,

i want to create an array of elements of different types, for exemple the first element can be a Boolean, String, Enum or Numeric...  I don't know what each element of the array will contain so i need to change it dinamically based on what i need to show on the front panel. 

I already tried to create a cluster made of an array of cluster, in the inner cluster i put the four variable elements (Bool,Enum... Ecc...) and with the property node i can set visible or invisible the elements to show only what i want but i have to use 4 variable for each array index, it work but is a bit foolish... How can i populate it dinamically? I use a second array to decide what type of data to choose... 

 

If you need more informations please ask, thank you 

Marco 

0 Kudos
Message 1 of 6
(96 Views)

All array elements have to be the same type! There is no exception. A roundabout workaround would be to use an array of Variants. But before you head down that dark alley, make sure you think twice and trice about it. Variants may seem like the easy way out but you buy it with dynamic datatypes, which means everywhere the value in the variants are used you have to do at runtime introspection into the variant to learn what type it contains, then convert it into a real world value to do your math or whatever else. A real pitta and it can blow your simple project up like a balloon.

Rolf Kalbermatter
My Blog
0 Kudos
Message 2 of 6
(87 Views)

@IlMarione wrote:

If you need more informations please ask, thank you 


That all sounds quite silly. Even if you have an array of clusters, you can not set the cluster element visibility for a particular array element. All properties are shared and identical for all array elements.

 

Maybe start with explaining in much more general terms what you are trying to achieve.

 

Is this mostly an indicator or also a control where these elements need to be operated by the user. Is this mostly for UI purposes or are you carrying this "data" across wires and subVI connectors, etc. Is the array size fixed or variable? Can you show us some code drafts?

0 Kudos
Message 3 of 6
(47 Views)

You can't dynamically change the control types at runtime- they all must be defined at compile time. And an array of clusters with one of each type will hold the data, but you can't change the visible appearance of each one independently.

 

What you COULD do would be to have a handful of indicators on your front panel with a separate scrollbar that you "treat" like an array. When the user "scrolls" the list, manually assign new formatting and data to your screen elements.

 

Another way to do this would be to use strings for everything and populate a table or something. For example, booleans can just say "T/F" instead of having a light.

0 Kudos
Message 4 of 6
(43 Views)

@BertMcMahan wrote:

Another way to do this would be to use strings for everything and populate a table or something. For example, booleans can just say "T/F" instead of having a light.


I was waiting for an answer to my question about control vs. indicator, but had a table in mind if the answer is "indicator" only. 😄

 

For booleans, the cell could be an empty string, but the cell background color could be unique for True vs. False. Of course the string could be informative too (True/false, On/Off, Open/Closed, In range/out of range, Pass/Fail, etc.)

0 Kudos
Message 5 of 6
(38 Views)

(A shameless plug for my own Datagrid implementation, should the OP want something similar... https://forums.ni.com/t5/QControl-Enthusiasts/The-DSM-Datagrid-yet-another-Datagrid-QControl/td-p/42...)

Message 6 of 6
(29 Views)