09-22-2011 06:50 AM
I have a dialog box that may pop up when no one is at the monitor. I would like to display a countdown timer in the dialog box that lets the operator know that he/she has so many seconds to make a decision before the program moves forward. Is there a way to make the dialog box update while it is displayed? Do I have to make this a sub VI or is there an easier way? Any suggestions?
Solved! Go to Solution.
09-22-2011 08:28 AM
Just have a loop and your time indicator inside the loop. Be sure to use a small delay in the loop so you don't make a Greedy Loop .
09-22-2011 08:54 AM
Thanks for the response, but I don't think I'm explaining myself very well.
The problem is more with the dialog box not updating. The timer is in a loop and runs in the background but you can't see the timer run while the box is open. I want the dialog box to say something like: "program will do X in Y seconds if the continue button is not clicked" I would like the Y to be a number that counts down to zero.
Hopefully this clarifies my question a little.
09-22-2011 09:31 AM
09-22-2011 09:51 AM
To the best of my knowledge, you won't be able to modify the built in dialog boxes to show a timer. This may actually be possible but I doubt it's easy.
In my opinion, you will have to use a subvi and display the front panel when called. Arrange the front panel to visually look like the dialog box you want to appear, with a numeric indicator. Feed the timeout value into the subvi (this will allow you to decide when to exit the while loop). Use the "Tick Count (ms)" inside and outside the while loop. The one outside will mark the time at which the subvi was called. Subtracting the two will give the change in time (how long the subvi has been running in ms). You can subtract this number from the timeout value, and wire this to the numeric indicator. This will provide the effect of a countdown.
If this value becomes less than zero, exit the while loop. Likewise, if the operator performs certain tasks, exit the while loop. On a side note, you can add a button to suspend the countdown. This will be useful if the operator gets to the screen with 2 seconds left.
09-22-2011 10:22 AM
While I was working up a quick example pjr1121 explained how to do it. That means I can just attach the example with no explanation
09-22-2011 10:56 AM
09-22-2011 11:10 AM
Thanks for the help. I was already marching down the subVI path, I was just hoping for a simpler solution.
09-22-2011 11:20 AM - edited 09-22-2011 11:22 AM
@ben64 wrote:
Steve, watch for the greedy loop! A refresh rate of 250ms will be sufficient in that case.
Ben64
Good catch, you are absolutely right! I fully intended to put that in there too. With all these cores and memory and gigahertz I didn't even notice and spaced it.
One more thing. This will block the loop it is called from. If that is a problem just put the dialog VI in another loop and use a notifier to execute it.
09-22-2011 11:50 AM
As an alternative solution, you could put the timer in the button of the dialog box. It is a simpler solution, but I doubt it would serve your purpose. Use a Two/Three Button Dialog.vi and wire the text for the buttons with the button name appended by the timer. So you could have an OK button that says OK (10) when it starts and counts down OK (9), OK (8), ...
Just a thought.