LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How can I get the indexes within an array control when I change a value

I have a front panel with a 2D arrays control (exemple: X=4, Y=16).

When I change a value inside  this array, I use a "value change"  event, and I would

like to know the indexes of the value which have been changed.

How can I do this ?

Francis 

 

 

0 Kudos
Message 1 of 10
(4,353 Views)

Hi Francis,

 

straight-forward solution:

Compare old (array) value with new ones - the event structure supplies you with both. Now check the resulting boolean array for a TRUE value... 

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
0 Kudos
Message 2 of 10
(4,348 Views)

For a 2D array, you could user Gerd's solution of comparing the two arrays (by element), converting the 2D boolean array to (0,1), then use "array max". The max index gives you an array with two elements, corresponding to the 2D indices of the changed element.

 

Since you are using an event structure monitoring FP activity, only once element will be changed per event. If the VI cannot handle the event immediately, several events will get queued up, one per changed element. 🙂

 

 If you also plan to change element using a value(sgnl) property, several (or zero) elements could have changed, so you would need to handle these cases with a bit more code. 🙂

Message Edited by altenbach on 08-13-2008 09:04 AM
0 Kudos
Message 3 of 10
(4,344 Views)

You can also track the index you are changing ( however we always know it 🙂 )  at some indicator,and add indication

of it change to the event handler that handles the change of the array.

_________________________________________________________________________________________________
LV 8.2 at Windows & Linux


0 Kudos
Message 4 of 10
(4,335 Views)

mishklyar wrote:

You can also track the index you are changing ( however we always know it 🙂 )  at some indicator,and add indication

of it change to the event handler that handles the change of the array.


 

Sorry, I I have idea what you mean. can you attach a small example?

 

(If I understand the problem correctly, we are talking about an array control on the front panel and we are trying to determine which element just got changed by the operator.)

0 Kudos
Message 5 of 10
(4,329 Views)

Hello altenbach,

 

May be something like this..it is 1D array for simplicity 🙂

 

Regards,

Michael 

_________________________________________________________________________________________________
LV 8.2 at Windows & Linux


0 Kudos
Message 6 of 10
(4,318 Views)

Well, Yes. If the array is resized to only show one element, this will work.

 

In the general case, the array is resized to show multiple elements, so this will only give you the element that currently shows on the upper left corner of the scrolled array, it does not indicate which element has been changed.

Message 7 of 10
(4,308 Views)
Always good to know something new 🙂
_________________________________________________________________________________________________
LV 8.2 at Windows & Linux


0 Kudos
Message 8 of 10
(4,299 Views)

Thanks a lot to everybody who answered.

I used the solution proposed by GerdW and Altenbach (make a compare and find the max of a boolean array) and this

perfectly adapted to my need (see vi atached)

Thansk again

Francis 

0 Kudos
Message 9 of 10
(4,269 Views)

A few minor comments:

 

  • To get the first two elements of an array, you should use index array, resized to two outputs. No need to wire the indices. (see attached).
  • It is silly to convert to a cluster and then unbundle. Even then, you should set the cluster size to two (right-click array-to-cluster...cluster size...).
  • You need to make absolutely sure that the 2D array size remains the same, because the code fails e.g. if you start out with an empty array and then change an element, forcing a new size. You might need to add some code to protect against that possibility.
  • I set the default to an array of zeroes of the displayed size to protect against the above scenario.
  • The current code does not need a shift register. (You might need it for more complicated scenarios, though).
  • Your cannot stop your VI directly unless you create an event for the stop button too.

 

Message Edited by altenbach on 08-14-2008 08:04 AM
Download All
Message 10 of 10
(4,256 Views)