Read Index of Array Element in Event Structure

Updated Oct 23, 2023

Reported In

Software

  • LabVIEW

Issue Details

I am using an array of controls on my LabVIEW frontpanel. If the user changes the value of one of the array elements, I want to trigger an event in an event structure and read the index of the modified element, how can I achieve this?

Solution

The event structure does not provide this information by default. You need to manually compare the old and new values of the array in order to get the index of the modified element. See this example for how to compare the elements:


Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.

This code was created for an array of buttons, but works the same way for all common datatypes.

Additional Information

If you are using an array of clusters, you have to modify the code to compare the cluster elements as well:


Note: This image is a LabVIEW snippet, which includes LabVIEW code that you can reuse in your project. To use a snippet, right-click the image, save it to your computer, and drag the file onto your LabVIEW diagram.