LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

button listener

If I have three buttons A, B, and C, and I have a listbox, and a button Insert. How do I make the listbox display the 3 buttons in the order that I clicked them? In other word, if I click button C first, then A, then B, then button INSERT, the listbox should display C, A, B. Thanks.
0 Kudos
Message 1 of 16
(4,027 Views)
Sounds like you want a loop that reads the buttons and checks whether each one has changed by comparing its value with the previous value (held in a shift register). Then when you detect a change, you append a value identifying the button that changed to an array held in another shift register. When you detect the insert button has been clicked, you exit the loop and your array contains the sequence in which the buttons were clicked.
0 Kudos
Message 2 of 16
(4,027 Views)
Your question screams Event Structure. I whipped up a quick example.

Daniel L. Press
PrimeTest Corp.
www.primetest.com
Message 3 of 16
(4,027 Views)
But how would I tell it the order. If both buttons A and B are pressed, and button B is pressed before button A, the loop will detect a change in button A first before it detects the change in button B.
0 Kudos
Message 4 of 16
(4,027 Views)
What are you doing inside the loop that will take so long that you can press the buttons faster than the loop time? This method should work, but the event method that Photon Dan suggested is probably better.
0 Kudos
Message 5 of 16
(4,027 Views)
Daniel,
Thanks a lot, that's exactly what I am looking for. I have not work with LabView Event Structure before so this is all new to me. So now if I want to delete all item or one item or move item up and down, do i just code like normal or does it have to be outside of the event structure? I saw in your code you have the 3 buttons in one event case with the build array function. So now if I want to delete items, do I have to build an entirely new event structure, then use the delete array function to delete items. Thanks much
0 Kudos
Message 6 of 16
(4,027 Views)
To delete listbox items, you can have some other button tied to a delete event. You can use the "Delete from Array" function to delete a selected item in that event case. You can add/delete more buttons or change the existing ones. If you add a button, you will need to add it to the list of handled events in that build array case.

- Dan
0 Kudos
Message 7 of 16
(4,027 Views)
Dan,

How do you delete items in the listbox according to the buttons clicked...same with insert, except now I want to delete after user click on either buttons A, B, and C? As of right now, I can only delete items that are highlighted in the listbox. Also, right now when you clicked on the button, it latched and then release, so if you hit it twice, it will put in two of the same buttons in the list. I tried changing it to "switch when latch," but it still put in the same name twice if you hit it twice. Is there a way the VI will remember the state of the button (true or false) then put the button in ONLY if it's true; so if the user turns the button on, then changes his/her mind and turns it off, it will NOT put the button in the li
st? Sorry I asked a lot of question, I hope you don't mind.

Thank you very much 😛
0 Kudos
Message 8 of 16
(4,027 Views)
Great example Dan,

I've added to it with a "delete" function. it will delete the element you've
highlighted in the listbox. You can also re-order the list elements by
enabling "Item Dragging" for the listbox.
And just to be sure, you can "output" your listbox elements into an array
to check you're edited listbox.

Dan, I do have a question for you though, Why is the functionality of the
controls different when they are placed of the inside the Event structure or
outside the event structure?

Regis


"analog" wrote in message
news:50650000000500000093350100-1066448259000@exchange.ni.com...
> Dan,
>
> How do you delete items in the listbox according to the buttons
> clicked...same with insert, except now I wa
nt to delete after user
> click on either buttons A, B, and C? As of right now, I can only
> delete items that are highlighted in the listbox. Also, right now
> when you clicked on the button, it latched and then release, so if you
> hit it twice, it will put in two of the same buttons in the list. I
> tried changing it to "switch when latch," but it still put in the
> same name twice if you hit it twice. Is there a way the VI will
> remember the state of the button (true or false) then put the button
> in ONLY if it's true; so if the user turns the button on, then changes
> his/her mind and turns it off, it will NOT put the button in the list?
> Sorry I asked a lot of question, I hope you don't mind.
>
> Thank you very much 😛



[Attachment Button_listbox_(PrimeTest).vi, see below]
0 Kudos
Message 9 of 16
(4,027 Views)
The booleans are latched so they will only "pop" back up to a false state if they are read by the execution system. The control terminals will only be read if they are inside the while loop and better yet, inside the event case that gets triggered by them.

Daniel L. Press
PrimeTest Corp.
www.primetest.com
0 Kudos
Message 10 of 16
(4,027 Views)