LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

programatically generating an event

Hi All,

Perhaps I have tunnel vision here, but can't figure why this isn't an
easy fix.

Problem: I have an event structure with 7 events. One of these
events (#3) removes a line of data from a table (indicator). It is
activated on a value change of the "remove state" button I have on the
front panel. Another event is a mouse up event (event #1) on the
table. All this does is highlight the table row where the mouse up
occured.

As it happens, after I delete a row I want to readjust the table row
highlight which requires the exact same code as in the table "mouse
up" event handler.

Is there a way for me to generate this "table mouse up" event to occur
and be processed immediately after the "remove state value change"
event execut
es?

I hate to duplicate code when I don't have to. It seems to me there
should be an easy way to immediately call event #1 after executing
event #3.

Thanks in advance for any input.

Gc.
0 Kudos
Message 1 of 5
(3,543 Views)
There was a similar question yesterday about running one event at startup as an initialization step. As Greg McKaskle suggested you can fix this not by duplicating the code but by putting the code in a sub-VI and just call that wherever you need it. Sub-VIs can operate on the properties of objects in the caller via references so that's no problem.

If you don't want to do that either you can create a user event that also fires the same event case. So if one event needs to be followed by another just make it set that user event...
0 Kudos
Message 2 of 5
(3,543 Views)
Hello,

If you find yourself needing this type of structure more than just this one time (a certain event must be followed by another event), then a state machine may be more appropriate for your application. A state machine consists of a while loop (with a shift register carrying the state) with a case structure inside. State machines require polling but can sometimes serve the purpose of the application more accurately than an event structure.

Happy New Year!

Liz Fausak
National Instruments
0 Kudos
Message 3 of 5
(3,543 Views)
Now there's an obvious answer! I told you I had tunnel vision. I
subVI'd the code in that event and am back on track. Sometimes you
just need to ask the question...

From an academic standpoint, I'd still like to know how to activate
one event from another but for now it's just out of curiosity. Thanks
Mads.

Liz, as for the classic state machine idea, I was adapting my state
machine program to the event structure (probably the reason for my
tunnel vision). It actually runs much cleaner under the event
structure than the classic polling state machine.

Happy New Year,

Gc.
0 Kudos
Message 4 of 5
(3,543 Views)
> From an academic standpoint, I'd still like to know how to activate
> one event from another but for now it's just out of curiosity. Thanks
> Mads.
>

Now that you have it working using the subVI, I'll add in the part about
generating events. There are times when each approach is useful, but I
tend to mention the subVI first because IMO the queued message handler
or can be a bear to debug.

The general way to fire some code via an event is to make a user event
that matches the terminals of the other event. Register for the user
event in addition to the other event, then fire the user event.

Greg McKaskle
0 Kudos
Message 5 of 5
(3,543 Views)