06-07-2021 07:09 AM
Hi experts,
May I know how to use the same button for multiple event cases? For example, I have a "enter" button that is used for several different purposes.
Is there a solution for this? Thank you in advance
06-07-2021 07:24 AM
Hi Timothy,
@timothysilverman wrote:
May I know how to use the same button for multiple event cases? For example, I have a "enter" button that is used for several different purposes.
Is there a solution for this?
You can not assign the same button to several event cases.
But you can implement a statemachine or (event-driven) QMH to handle the button event as needed…
06-07-2021 07:27 AM
Hi GerdW,
Are there any examples which I can refer to?
Thank you!
06-07-2021 07:32 AM
06-07-2021 10:23 AM
@timothysilverman wrote:
May I know how to use the same button for multiple event cases? For example, I have a "enter" button that is used for several different purposes.
If enter is pressed, what determines the purpose? How does the code know? Is there e.g. an enum that indicates state?
Why not use a single event case containing a case structure with one case for each "purpose", whatever that means. State?
Can you take a step back and tell us what problem you are trying to solve, not how you are trying to solve it. I am sure there are much better solutions.
06-08-2021 01:06 AM
Hi altenbach,
The problem I'm trying to solve is to have a button to handle several event structures. Just like I mentioned before, the "enter" button will be needed to execute several event structures, and I'm wondering how I can make it work.
For example,
1. I need the "enter" button to accept the user input and verify the user.
2. I need the "enter" button to also handle the mathematic calculation that the user enters.
I hope there is a way to do this, thank you
Best regards,
timothysilverman
06-08-2021 01:26 AM
Hi Timothy,
there still is a lot of "how" and not so much "what"…
Why are there "several event structures" in your VI? There should be only one!
(Well, there can be more than one, but as you are asking basic questions about using event structures I guess you are not experienced enough to use several event structures within one VI.)
@timothysilverman wrote:
For example,
1. I need the "enter" button to accept the user input and verify the user.
2. I need the "enter" button to also handle the mathematic calculation that the user enters.
06-08-2021 01:41 AM
Usually if i need several events executed by one action, i daisy-chain hidden controls, which then get updated by event cases.
I think i've only done what you need once tho, because events are usually separate things (so it's PITA to trigger them all) and it just so happened that i needed them triggered sequentially.
What GerdW suggested seems more reasonable.
06-08-2021 01:50 AM
Hi GerdW,
Indeed I am new to LabView.
I will try to apply the ValueChange to my vi
Thank you
06-08-2021 03:51 AM
Hi Timothy,
As has already been suggested, the ValueChange events for each input might be what you're looking for (and they're certainly likely to be easier to use).
However, I'm curious about your use of the term Enter. Do you mean you have a (LabVIEW) button with the text "Enter" or are you talking about the keyboard enter/return key?
The latter can be integrated with an Event Structure using the Key Down event in the <This VI> category.
You could then use the VKey output to determine if Enter/Return was pressed, and then evaluate what to do based on the FocusObj, maybe (if you have the focus in a control that you're entering data for).
See the example here (note that the "boolean" input doesn't work in a useful way, because it can't have easily input focus - although you can bind it to a keyboard shortcut and then give it focus...)
For this example, I'd definitely pick the ValueChange event instead, which would make it much easier to handle the appropriate datatypes. But maybe your use case has some features which you haven't described fully here, and those could maybe make this useful?