Introduction
If you have a bunch of identical controls on your front panel, you might want to put those into an array so that you can perform the same action for each one of those controls. However, by putting them in an array, each control must have identical properties which means they cannot be customized independently of eachother. You could duplicate the code for each control individually. However this code shows a way of using a cluster, which can have different elements, like an array, that can be autoindexed and iterated over using a FOR loop.
Steps to Complete
This code has a control type with a boolean and a string control in a cluster, and then there are two each of those controls. The prupose of the code is to monitor these controls and make the string control disabled and greyed out unless the boolean value is checked. When the start button is pressed, the data is compiled into arrays of the component data and passed along to whatever codemust use the data. The action is repetative, but the properties are unique.
The method on the left requires the same code to be repeated on the block diagram once for each instance of the control. The method on the right clusters the controls together, and then uses an array of references to the controls within to iterate the same function over all of the controls in the cluster.
Additional Notes
Add additional notes here...
Example code from the Example Code Exchange in the NI Community is licensed with the MIT license.
Thanks for posting this example, it is a really useful idea. I have one quibble, perhaps the example should be named "how to process multiple instances of the same cluster". If the clusters are not all the same this method does not work.
Unfortunatley, there really isn't a way to do this with diffrent types of clusters because you have to prototype the cluster after you cast the data to the cluster class. You could do this if you made an error handler that cycled through you various types of clusters and tried to cast the variant to each one until one works. That would make the program significantly more complicated though.
On the other hand, if you made custom LV classes for each type of cluster, you could cast them to their specific type, and avoid prototyping.
I think I have found a way to make this work with semi-arbitrary datatypes using the method you posted. Inside of the cluster, each piece of "real" data needs an associated enum that indicates the datatype of the data. Then when you recast the variant to cluster, you use variant datatype for the "real" data. Use the enum to select how to cast the variant.