From Friday, April 19th (11:00 PM CDT) through Saturday, April 20th (2:00 PM CDT), 2024, ni.com will undergo system upgrades that may result in temporary service interruption.

We appreciate your patience as we improve our online experience.

LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

How to get the index of a pressed button in control array?

Solved!
Go to solution

Greetings,

 

I have 3 parallel arrays--one containing buttons and the other two containing string indicators.  I'd like to be able to push a button and get the values in the other arrays.  How can this be done?

 

(P.S.  Illustrations are great and most welcome, but I do not have Labview on this computer, so I would appreciate it in jpg or screenshots if possible.)

 

Thank you!

0 Kudos
Message 1 of 8
(11,811 Views)
Instead of an array of Booleans, you should use a radio control if you only want one of the buttons to be true. The output would be wired directly to an Index Array function.
0 Kudos
Message 2 of 8
(11,804 Views)

Use an event structure for a value change of the boolean array.

 

Do a "not equal" comparison on the "new value" and "old value" event terminal, the use "search array" on the result to find the TRUE element. The output will be the index of the changed element. If you want latch action, reset the boolean array control to all false using a local variable.

0 Kudos
Message 3 of 8
(11,797 Views)

Here's what I had in mind. Modify as needed.

 

Download All
Message 4 of 8
(11,789 Views)
Solution
Accepted by topic author newbo

@altenbach wrote:

Here's what I had in mind. Modify as needed.

 


If you have the buttons initalized to all false, then you don't need to perform the Not Equal To.  Just do a search with the NewVal.  The local variable to reset the buttons should be wired to the OldVal.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
0 Kudos
Message 5 of 8
(11,783 Views)

@crossrulz wrote:
If you have the buttons initalized to all false, then you don't need to perform the Not Equal To.  Just do a search with the NewVal.  The local variable to reset the buttons should be wired to the OldVal.
Currently, the button array stays on the selected element for positive user feedback. Immediately resetting to false might confuse the user and we would need another indicator to show which was was pressed last.
(Your method is a bit dangerous in the general case, where e.g. several buttons could get changed at the same time from elsewhere in the program via locals.) Still, I agree my code is only one of many possible ways to do this.

 

Message 6 of 8
(11,777 Views)

Ah, I see what you're doing with it now.  The only problem would be if somebody deselected the button.

 

Yes, my implementation was with the assumption that that was the only code affecting the value.


GCentral
There are only two ways to tell somebody thanks: Kudos and Marked Solutions
Unofficial Forum Rules and Guidelines
"Not that we are sufficient in ourselves to claim anything as coming from us, but our sufficiency is from God" - 2 Corinthians 3:5
Message 7 of 8
(11,773 Views)

My current implementation does not allow deselection. If the user tries, that button is detected as changed and will be set true again immediately. All this can easily be fine tuned as needed.;)

0 Kudos
Message 8 of 8
(11,760 Views)