kodon1 Posted January 7, 2015 Report Share Posted January 7, 2015 Hi, I have a task which I'm struggling to complete. I have a GUI with a 'Cancel' button which causes to GUI to close. I want to add a functionality where the GUI will also be closed if after 30 sec automatically. I thought that the right programming approach is to force a press on 'Cancel' button from within the code. I used the val(sgnl) property but it didn't work well - it just pressed on the button regardless what was the input T or F to the property. I tried to use an event with some dummy indicator that should operate the event upon value change, but it also didn't work... I implemented the timer inside a for loop, which also might be wrong. anyhow, I'd be happy to get a couple of suggestions how to make it work. thanks Quote Link to comment
ned Posted January 7, 2015 Report Share Posted January 7, 2015 The easiest way to do this is with the Timeout event in an event structure. The event structure handles the Cancel button (and whatever other buttons), and you set the Timeout for 30 seconds (30,000 msec). Quote Link to comment
kodon1 Posted January 7, 2015 Author Report Share Posted January 7, 2015 Hi Ned, thanks for the reply. Just to add a little more details... how will this event be called? can I attach an event to a timer? I mean what will invoke this event? also - there are other activities that take place in the GUI - there is also an OK button which under some conditions can also close the GUI, and if OK is pressed it should restart the timer to 30 sec again. with that additional information, could this solution still hold? thanks Quote Link to comment
jcarmody Posted January 7, 2015 Report Share Posted January 7, 2015 The easiest way is as ned said, shown in the top image. If you can't use a 30-second timeout because you need to handle other things during those 30 seconds, the lower loop will evaluate whether 30 seconds has elapsed every 0.025 seconds. You'll need to pass the "reset timer' command back into the Timeout event using a Shift Register. Maybe post your VI? Are you really using LabVIEW 2015? Quote Link to comment
kodon1 Posted January 7, 2015 Author Report Share Posted January 7, 2015 Hi jcarmody, tx for your reply. I'll try to put a snap of the subVI for a better description. I'll try to use your suggestion and see what comes out of it. If I didn't mention before, I already have an event that controls the 2 other buttons in the vi. so I think that I can just add another one... I'll post it here in a few hours. thanks Quote Link to comment
hooovahh Posted January 7, 2015 Report Share Posted January 7, 2015 If I didn't mention before, I already have an event that controls the 2 other buttons in the vi. so I think that I can just add another one... It is generally best to have only one event structure in a VI. It isn't required by any means but having multiple event structures can make understanding the code more difficult, and can make bugs if certain behavior isn't avoided. Once you code is posted it should be no problem describing the best approach. Quote Link to comment
jcarmody Posted January 7, 2015 Report Share Posted January 7, 2015 It is generally best to have only one event structure in a VI. [...] Just to be clear, I showed two Event structures just to show the two approaches. Pick whichever one suits your application, although it sounds like the upper one isn't applicable with the other events you need to handle. Quote Link to comment
kodon1 Posted January 8, 2015 Author Report Share Posted January 8, 2015 hi, just wanted to update that the second solution (event with a timer) did the trick. i will need to solve a few other bugs that happened due to the logic change but the final result seems to be very good. thanks a lot to all who helped Quote Link to comment
eberaud Posted January 8, 2015 Report Share Posted January 8, 2015 It's a good idea to set the post as "Answered" and define which post is the answer, so that other users seeing this thread can go directly to the solution Quote Link to comment
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.