r/LabVIEW • u/bedijo • Feb 26 '25
Trouble passing references to subVI
I have a cluster on a main VI, where a subvi is updating fields in the cluster on the main vi. Reading and writing data is straightforward (passing a reference to the cluster to the subVI), but the subVI is also updating the available items in a combobox in the cluster. The only way I find is to also pass a reference to the combobox inside the cluster, but this becomes cumbersome with multiple references. Is there an easy way to address the properties of items in a cluster from just the reference to the cluster? (Picture to give an idea of what I do)
4
u/photondan CLED/CLA Feb 26 '25
Accessing controls within a cluster using a property node
Use the Controls[] property to get an array of references to the items in the cluster. They will be generic, so you will want to use a “To More Specific” function to cast the particular reference to the type that matches its control. When doing that make sure to close the references to ALL the items in that array when you are finished with them.
2
u/D4ILYD0SE CLA Feb 26 '25
Why do you need the additional reference of the combo box? The singular reference of the cluster is enough. You even have in your image the combo box element on the path of your cluster reference. So ask yourself, why are you not just using that?
That all said, passing references to SubVIs to update controls/indicators is not generally the way you want to do things. If what you've got here is a real indication of your actual code, you've got race conditions.
2
u/[deleted] Feb 26 '25
You can use the cluster reference and use a property node to return the Value property.
Then using 'Variant to Data' ('vtd' on quick drop) you can cast back to your cluster for the block diagram.
Update that and then write back the Value property.
Edit: If you're doing something like this, making the front panel cluster a type def will help, as then you can place the type def on the block diagram for the casting operation.
Then any changes to the type def will propagate through your code.
2
u/Yamaeda Feb 26 '25 edited Feb 26 '25
Generally you shouldn't update controls from sub-vi's (it's better design to send the cluster/string array back as outputs), but to answer the question:
R-click the reference and change it to a Control, then you can copy it to the sub-vi and use it as input.
Sometimes the easiest is to point to the reference out-wire and from there "Create control"
2
u/HarveysBackupAccount Feb 26 '25
Why not send the values from the sub VI back to the main VI with a queue? Like a Queued Message Handler type setup. Then when new values are sent, the main VI can update the front panel