LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Passing an array control reference - accessing all values

I have a top level VI containing an array control.
I'd like to pass to a sub VI a reference to the control, such that I can access all the values in the array.
At present when I create a reference and pass it to my sub VI, I only seem to have access to the value of the zeroth array element.
Please can anyone help?
Many thanks.

Nick
0 Kudos
Message 1 of 8
(3,814 Views)
When you create the reference, make sure you do it for the array and not the element itself. Right click on the either the index control or the outer or the very outer ege of the array control that surrounds the element and select Create >Reference. The reference on the subVI should have an icon that looks just like the icon for an array on the Controls palette.
Message 2 of 8
(3,808 Views)
Dennis,
Many thanks for that help. I just discovered the same thing myself! Alternatively, I guess one could create the array control, right-click to create a reference to it, and only then drop a control of the right sort onto it to determine its type.
It can be a little fiddly otherwise.
Nick
0 Kudos
Message 3 of 8
(3,805 Views)
Create the reference from the terminal on the block diagram.
Message 4 of 8
(3,796 Views)

Just as a side question, I'm wondering why you're passing a reference just to get access to the array values. Passing the array itself would be a much more efficient means.


Property nodes cause data copies and the execution engine to switch to the user interface thread. It's best to try and avoid them if all you're doing is reading the data.

A wire is always the best route. (pun intended)Smiley Wink

Ed



Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
Message 5 of 8
(3,790 Views)
"Passing the array itself would be a much more efficient means."
Umm. I'm not sure I understand that. Surely if I pass an array from one VI to a sub VI all the data in the array is being replicated in the sub VI. I was working from the "traditional" programming paradigm where "pass by reference" means that data is not copied, and "pass by value" means that it is.
Please can you explain?
0 Kudos
Message 6 of 8
(3,773 Views)
OK, here's where LabVIEW (or G) differs from many other languages.

The LV compiler is pretty good at working out where data copies are required, and passing an array to a sub-vi will only result in a copy (pass by value)  if the array is modified and fed back into the program in a parallel wire.  If the array is modified and fed through (not parallel), then no copy will be made (pass by reference).

This is basically the same as pass by value and pass by reference, except the compiler pretty much works things out itself according to what's best.  All you need to do is wire it up.  Of course with time, you'll learn to predict when copies are made (in LV 7.1 it's kind of easy) and can then avoid them using specific programming techniques.

Passing a LV reference involves using VI server and so on and is coupled with relatively large overhead, so if you don't really need it, don't do it.
You can't compare LV references with traditional "Pass by reference" convention.

If I've made any glaring mistakes, someone please correct me.

Hope this helps

Shane.
Using LV 6.1 and 8.2.1 on W2k (SP4) and WXP (SP2)
Message 7 of 8
(3,767 Views)
Well put Shane.

What it comes down to with LabVIEW is never use a property node, local/global variable or reference if you can do the same thing with a wire.

Ed


Ed Dickens - Certified LabVIEW Architect
Lockheed Martin Space
Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
0 Kudos
Message 8 of 8
(3,749 Views)