Jump to content

Timer with GUI, little need help here


Recommended Posts

Hi guys,

Im trying to make a simple GUI timer, where you can insert the number of seconds and at the end of the countdown it plays a sound.

Ive searched the forums and found a lot of examples using timediff and timeinit and a few not using them.

Thats how i built the code, but im missing something... Can you help me out plz ?

Dim $timer

#include <GUIConstants.au3>

GUICreate("", 180, 120)
GUISetState(@SW_SHOW)
;#######################################################################
GUICtrlCreateLabel("Timer", 10, 15, 40)
$timer = GUICtrlCreateInput("", 45, 10, 40, 20, $ES_NUMBER)
GUICtrlCreateLabel("seconds", 90, 15, 90)
;#######################################################################

$ok = GUICtrlCreateButton("Ok", 40, 50, 60, 20)

While 1
   $event = GUIGetMsg()
   Select
      Case $event = $ok
    $t = Int(GUICtrlRead($timer))
         ExitLoop
      Case $event = $GUI_EVENT_CLOSE
    Exit
        ExitLoop
   EndSelect
WEnd
GUIDelete()

While 1
   Sleep(50)
WEnd

Func timer()
While 1
        Sleep($t * 1000)
        If $t = 0 Then
            SoundPlay("C:\Windows\media\tada.wav")
        EndIf
WEnd
EndFunc

Thx again guys ! :P

Link to comment
Share on other sites

I tested 5 min and changed a lot of your code:

#include <GUIConstants.au3>

GUICreate("", 180, 120)
;#######################################################################
GUICtrlCreateLabel("Timer", 10, 15, 40)
$timer = GUICtrlCreateInput("", 45, 10, 40, 20, $ES_NUMBER)
GUICtrlCreateLabel("seconds", 90, 15, 90)
;#######################################################################
$ok = GUICtrlCreateButton("Ok", 40, 50, 60, 20)
GUISetState()

While 1
   $msg = GUIGetMsg()
   Select
      Case $msg = $ok
    Do
        $time = GUICtrlRead($timer) - 1
        Sleep(1000)
        GUICtrlSetData($timer, $time)
    Until $time = 0
    SoundPlay("C:\Windows\media\tada.wav")
      Case $msg = $GUI_EVENT_CLOSE
    Exit
        ExitLoop
   EndSelect
WEnd

This works on me. :P

Link to comment
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
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...