From 04:00 PM CDT – 08:00 PM CDT (09:00 PM UTC – 01:00 AM UTC) Tuesday, April 16, 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: 

Handle one case with different type sources in Event Structure

Solved!
Go to solution

System:
LabVIEW 2014
Windows 10

 

Hello, I am struggling on a simple problem which is triggering an event structure with different event sources, for which I could not find an answer in the forum . I want to run a piece of code either when I press a button or when I press a specific key: the spacebar.

In the attached VI I am able to do one or the other (where I use the ScanCode of the key spacebar to trigger a case with the code I want to run), but when I try to combine the two, I receive this error 

rpicazof_0-1612186636195.png

I have already checked that it is simple to have multisource event with the same type (e.g. two Booleans or two key downs) but I am sure there must be an simple solution for this, since this seems like a very common situation.

 

I would appreciate very much any help you guys could send my way, thanks!


PS: I leave a Disable structure so that the code can compile without considering the problem.


0 Kudos
Message 1 of 16
(1,236 Views)

Hi rpicazof,

 

simple solution: use two event cases!

Place the common code in a subVI (in both events) or in a case structure after the event structure...

Best regards,
GerdW


using LV2016/2019/2021 on Win10/11+cRIO, TestStand2016/2019
Message 2 of 16
(1,230 Views)

I would consider the easiest solution is put whatever code is inside the event structure in a subVI, and just have two different event cases that both call that subVI.

Message 3 of 16
(1,229 Views)

Hi GerdW and RavensFan,

 

thank you very much for the quick response! Definitely what you suggest would work, but I discarded this idea since the code I want to implement is absolutely humongous and embedded in a very dense front panel that I don’t want to detach. It seems strange that event structure cannot handle this situation… I was wondering if using some kind of  “variant” would do the trick, but I could not figure it out.

0 Kudos
Message 4 of 16
(1,189 Views)

If you want to keep the code in one event case, there are two possible solutions:

 

  • Have the code in the button value change event and create a second event for the key up event. Place a proberty node "Value(Signaling)" into that event, and wire a TRUE to it. This way, whenever the space bar is pressed, a click on the button is simulated, which will also trigger the event structure. This only works when the button is a latch, and the button event shoult reset its value back to False.
    This is quick and dirty, but works.
  • Create a user event, register for it, and wire it to the UserEvent Terminal of the event structure. You will then get a new type of event, where you place your code.
    Then, create an event for the button as well as for the key, which both will generate such an event.

UE.png

Message 5 of 16
(1,182 Views)

@rpicazof  ha scritto:

Hi GerdW and RavensFan,

 

 the code I want to implement is absolutely humongous and embedded in a very dense front panel that I don’t want to detach


This is an indication of bad design. No code should be allowed to be humongous.

Anyway, you can put your code in a third event that you can trigger programmatically.

The quick-and-dirty way in those cases is to add a hidden boolean control and use its Value (signaling) property to trigger its Value Change event.

Paolo
-------------------
LV 7.1, 2011, 2017, 2019, 2021
Message 6 of 16
(1,180 Views)
Solution
Accepted by topic author rpicazof

If you right-click the button and go to "Key Navigation" you can set a key to toggle the button. You can't use spacebar, but you could use any of the function keys (F1-F12), Clear, Delete, End, Page up/down, etc.

 

You could also create an event case to handle the Space bar button press that toggles the Value Change (SIgnaling) event of your OK button (unless it's latching, in which case you can't have a Value Change (Signaling) property node)

 

Overall yes, one case can handle two events, BUT the events must return the exact same data. Since the "OK" button press event doesn't return a Scan Code value, it won't let you do that.

 

Consider this- what would you expect the value of Scan Code to be when you clicked the OK button instead of the keyboard? It would be undefined.

Message 7 of 16
(1,176 Views)

I would use a different key than the <space bar>.  That's too common a key to be using like that.  What if I am editing text and your application takes focus away from the editor and I hit the <space bar>?  Now, if you're thinking about how the Windows API makes a button in focus respond to the <space bar> as a "click", I do believe LabVIEW buttons with focus respond the same way by default.

Bill
CLD
(Mid-Level minion.)
My support system ensures that I don't look totally incompetent.
Proud to say that I've progressed beyond knowing just enough to be dangerous. I now know enough to know that I have no clue about anything at all.
Humble author of the CLAD Nugget.
0 Kudos
Message 8 of 16
(1,166 Views)

Hello Sebastian.Weber ,

 

Thank for your response, could you send this snippet or VI file for the 2014 version? Many thanks!

0 Kudos
Message 9 of 16
(1,162 Views)

You can also but a case structure after your Event structure, where you can put code required by more than one Event.

0 Kudos
Message 10 of 16
(1,131 Views)