LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to set the value of an array element (not the complete array) by using a reference?

My situation is that I have an array of clusters on the front panel. Each element is used for a particular test setup, so if the array size is three, it means we have three identical test setups that can be used. The cluster contains two string controls and a button: 'device ID' string, 'start' button and 'status' string.

In order to keep the diagrams simple, I would like to use a reference to the array as input into a subvi. This subvi will then modify a particular element in the array (i.e. set the 'status' string).

The first problem I encounter is that I can not select an array element to write to by using the reference. I have tried setting the 'Selection s
tart[]' and 'Selection size[]' properties and then querying the 'Array element' to get the proper element.

If I do this, the VI always seems to write to the element which the user has selected (i.e. the element that contains the cursor) instead of the one I am trying to select. I also have not found any other possible use for the 'Selection' properties, so I wonder if I am doing something wrong.

Of course I can use the 'value' property to get all elements, and then use the replace array element with an index value, but this defeats the purpose of leaving all other elements untouched.

I had hoped to use this method specifically to avoid overwriting other array elements (such as happens with the replace array element) because the user might be modifying the second array element while I want to modify the first.

My current solution is to split the array into two arrays: one control and one indicator (I guess that's really how it should be done 😉 but I'd still like to know ho
w to change a single element in an array without affecting the others by using a reference in case I can use it elsewhere.
0 Kudos
Message 1 of 4
(3,459 Views)
I've attached a link that appears related to your situation, if not exact, perhaps it will steer you closer.
Good Luck, Doug

http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&B36BB3461DFDB44C86256931005D3210&cat=2E4161187E3DEB30862568660020BCC8
0 Kudos
Message 2 of 4
(3,459 Views)
> My situation is that I have an array of clusters on the front panel.
> Each element is used for a particular test setup, so if the array size
> is three, it means we have three identical test setups that can be
> used. The cluster contains two string controls and a button: 'device
> ID' string, 'start' button and 'status' string.
>
> In order to keep the diagrams simple, I would like to use a reference
> to the array as input into a subvi. This subvi will then modify a
> particular element in the array (i.e. set the 'status' string).
>
....

It isn't possible to get a reference to a particular element within an
array. There is only one reference to the one control that represents
all elements in the array.

While it may seem better to use references to update
an element within
an array, it shouldn't really be necessary, and it can also lead to
race conditions. If you write to an element that has the
possibility of the user changing, whether you write with a local, a
reference, or any other means, there is a race condition between the
diagram and the user. LV will help with this to a certain extent,
especially for controls that take awhile to edit like ones that use
the keyboard. In these cases, if the user has already started entering
text, it will not be overwritten by the new value unless the key focus
is taken away from the control first. It is similar when moving a slider
or other value changes using the mouse. LV will write to the other values,
but will not rip the slider out of the user's hand.

To completely avoid race conditions, you can split the array into user
fields and indicators that are located underneath them. Or, if some
controls act as both, you can do like Excel. You don't directly type
into the cell. You choose w
hich cell to edit, but you modify another
location. When the edit is completed, it is incorporated into the
display so that it is never lost.

Greg McKaskle
0 Kudos
Message 3 of 4
(3,459 Views)
Hi Greg,
I think that I have a similar question, except I am using a cluster. My program has about 20 controls for each channel, which are bundled into an indexed array of clusters. Some of these controls are purely set by the user, such as if the channel is on or off or the length of the trial. Some of the controls are determined by the program as it is run, such as the time that the last datapoint was written or if the channel has been calibrated. First, I am not sure of the best way to update the cluster. Would there be a benefit to using shift registers over a cluster global variable? Second, how can I completely ensure that race conditions will not occur?
Thanks very much for your help.
Emily
PS I have attached my vi if that is any help, althou
gh it is far from finished.
0 Kudos
Message 4 of 4
(3,459 Views)