Smitro Posted May 4, 2011 Posted May 4, 2011 Hi all,I'm wanting to build a simple app that counts down for about 20 mins and then plays a sound at the same time it should show the remaining time, and does the same thing over and over all day.I'm not sure what the best way to do this is.Idea 1:Set Timer.Sleep for 1 mins and check timer get status.Update Display.If Timer is found to equal 20 mins then play sound.Repeat.But will the timing be out using this method?Will the clock be waiting for the sound to finish playing before it's reset? Will the display be wrong because it takes time to process? Should the sleeps be ever 15 mins to be more accurate?Is there a better way to perform the same task?
hannes08 Posted May 4, 2011 Posted May 4, 2011 Hi Smitro, You can use TimerInit and TimerDiff to determine your 20 Minutes. SoundPlay will by default continue the script whilst playing a sound. (You can change that behavior by parameter) You can update your GUI's display by 1 sec if you like, but then it will be blurred by a second. Regards,Hannes[spoiler]If you can't convince them, confuse them![/spoiler]
Smitro Posted May 5, 2011 Author Posted May 5, 2011 Only thing I'm stuck on is allowing the user to close the window. How do I make this work? If you hit the close button, nothing happens. While 1 Sleep (2000) update_time() $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit EndSwitch WEnd
sahsanu Posted May 5, 2011 Posted May 5, 2011 How do I make this work? If you hit the close button, nothing happens.Remove the Sleep. That Sleep(2000) is blocking your script to get GuiGetMsg event.
Smitro Posted May 5, 2011 Author Posted May 5, 2011 Remove the Sleep. That Sleep(2000) is blocking your script to get GuiGetMsg event.Yes, but I need it to run update_time() every 2 seconds.
sahsanu Posted May 5, 2011 Posted May 5, 2011 (edited) Yes, but I need it to run update_time() every 2 seconds. Paste your entire script to check what we can do to solve this. Edit: A version of your script using GuiOnEventMode instead of GuiGetMsg, so you should have no problems with your sleep and close button. #include <GUIConstantsEx.au3> Opt("GUIOnEventMode", 1) $guiExample = GUICreate("Example") GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit") GUISetState(@SW_SHOW) While 1 Sleep(2000) update_time() WEnd Func update_time() ;Here goes your stuff EndFunc ;==>update_time Func _Exit() MsgBox(64,"Exit", "Have a nice day",10) Exit EndFunc ;==>_Exit Edited May 5, 2011 by sahsanu
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now