Sign in to follow this  
Followers 0
Smitro

Set Interval Equivelent

8 posts in this topic

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?

Share this post


Link to post
Share on other sites



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]

Share this post


Link to post
Share on other sites

Thanks for the advice I'll give it a go.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

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.

Share this post


Link to post
Share on other sites

#7 ·  Posted (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 by sahsanu

Share this post


Link to post
Share on other sites

Perfect. Thank you!

Share this post


Link to post
Share on other sites

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 account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0