LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

Strange Array Behavior When Getting Values

Solved!
Go to solution

I have an array that holds TypeDef'd controls and I need to get a reference to the control of each element individually. In order to do this I use the Index Values property of the array which I set to the index of the element that I want to get. From there I can get a reference to the control. This happens whenever the array value is changed via a simple Value Change Event

 

When changing the value of an element and then using the Index Values property to get the control reference at that index, the control reference that is returned is not the one that should be. What seems to happen is when I change an element in an array, that element automatically becomes the "0" index within the array itself. It's very strange behavior and I've been trying to get around it for a little while. I've attached images of the VIs that I am using to show you everything.

 

In the first picture I highlighted the important portions in green. Going from left to right, the first green box shows that I am setting the index at which the array should be starting at to 0. The reason I do this is because it's possible that the index display can be changed to another value and offset from what we expect it to be (0). Within the for loop I set the Index Values property to whatever the value of i is. This, in theory, loops through all elements within the array and then I get the value and reference of that element. In the probe window you can see the different values of the wires and I'll refer back to this in a second.

 

In the second picture you can see the value of the array on the actual front panel. The values of the probes in the first picture were taken after I changed the value of one of the properties in the "Alarm 7" row. From the front panel value you can clearly see that the index value of "Alarm 7" is 2, yet when looking at the probe in the first picture it shows that it is at index 0. Does anyone know why this is happening and how to get the references at their actual indexes?

 

1.

Screenshot_3.png

 

2.

Screenshot_4.png

0 Kudos
Message 1 of 17
(3,732 Views)

Index Values property node does not index the array, as you are expecting.  It modifies an array control to display the selected row/column pair in the top-left corner of the control.  What you are looking for is the Index Array VI in the array palette. 

 

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 2 of 17
(3,720 Views)

Ok that makes sense, but the Index Array VI won't work for me because I need to be able to get the control reference to the element, not just the value alone.

0 Kudos
Message 3 of 17
(3,718 Views)

Please attach the code.

 

You are using the wrong property. Index Values (see context help) is the property which defines the first element you SEE on the panel. However, it does NOT define the 'active' element.

 

Norbert

 

EDIT: After thinking twice on this, your request makes no sense at all. You are (hopefully) aware of the fact that all elements share the exact same properties except one: the value. So if you need the reference to recolor, resize or whatever (except modifying the value) THIS IS NOT GOING TO WORK.

Norbert
----------------------------------------------------------------------------------------------------
CEO: What exactly is stopping us from doing this?
Expert: Geometry
Marketing Manager: Just ignore it.
0 Kudos
Message 4 of 17
(3,715 Views)

What exactly do you want to do with the "control reference to an element". For instance, I don't think you would be able to change the background color of a single element to green, because that is a property of the entire array. To just obtain and write values you do not need a reference to the array, you can read and write from the array directly.

0 Kudos
Message 5 of 17
(3,712 Views)

I've attached the two VIs that are directly involved with the issue. I understand that it's the first value that it sees and that is why I thought setting it to 0 before processing the data would have worked.

Download All
0 Kudos
Message 6 of 17
(3,709 Views)

It has to do with another VI that I am using which requires a control to be sent in through a terminal. It is meant to be dynamic for any generic control to go through and it will get information from the control based on what it is. For example if it's a TypeDef'd control it will notice that and do something with it. It then goes through all of the controls within it (if it's a typedef) and does the same thing recursively. I am taking controls and saving their values to an XML file.

0 Kudos
Message 7 of 17
(3,704 Views)

I don't believe the index of an array control cuts any data off when you use the array as an input to some other function, so I don't think you have to worry about setting it to zero.

0 Kudos
Message 8 of 17
(3,703 Views)

Well the problem that I ran into was if I set the index to, say, 3, when I came back to process the data again, that index will still be on 3 even though I expect it to be on 0. Because there's no guarentee it is on 0, it's better to just set it to 0 in case it isn't.

0 Kudos
Message 9 of 17
(3,700 Views)

What exactly are you wanting a reference to?  If you want to write these values to an XML file (this assumes you have an array of clusters):

Capture.PNG

aputman
------------------
Heads up! NI has moved LabVIEW to a mandatory SaaS subscription policy, along with a big price increase. Make your voice heard.
0 Kudos
Message 10 of 17
(3,687 Views)