Jump to content

Timer help.


 Share

Recommended Posts

I'm trying to get this volume thing to work. It works, but I need it to make the GUI disappear after one second. But my timer returns 274066 and goes up. What is the problem here?

#include <GUIConstants.au3>
Dim $time
Dim $time_c
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Volume", 206, 37, @DesktopWidth-215, 50)
$Progress1 = GUICtrlCreateProgress(8, 8, 105, 17)
GUICtrlSetData(-1, 50)
$Label1 = GUICtrlCreateLabel("Volume: 50", 120, 8, 70, 17)
GUISetState(@SW_HIDE)
#EndRegion ### END Koda GUI section ###
SoundSetWaveVolume(50)
HotKeySet("{PGUP}", "up")
;~ HotKeySet("{PGDN}", "down")
While 1
    ;;;;; DEBUG ;;;;; GUICtrlSetData($Label1, $time_c)
    $time_c = TimerDiff($time)
    $time_c = Round($time_c, 0)
    If $time_c = 1 Then
        GUISetState(@SW_HIDE)
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func timer()
    $time = TimerInit()
EndFunc

Func up()
    $cVol = GUICtrlRead($Progress1)
    SoundSetWaveVolume($cVol + 5)
    GUICtrlSetData($Label1, "Volume: " & $cVol + 5)
    GUISetState(@SW_SHOW)
    
EndFunc

[left][sub]We're trapped in the belly of this horrible machine.[/sub][sup]And the machine is bleeding to death...[/sup][sup][/sup][/left]

Link to comment
Share on other sites

Initiate your timer by calling the timer() func right before your while loop. Also, you should use the "greater than or equal to" operater rather than equal to. The chances of the value being exactly 1 is slim. As well, it will count in milliseconds, not seconds. Something like this:

#include <GUIConstants.au3>
Dim $time
Dim $time_c
#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Volume", 206, 37, @DesktopWidth-215, 50)
$Progress1 = GUICtrlCreateProgress(8, 8, 105, 17)
GUICtrlSetData(-1, 50)
$Label1 = GUICtrlCreateLabel("Volume: 50", 120, 8, 70, 17)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###
SoundSetWaveVolume(50)
HotKeySet("{PGUP}", "up")
;~ HotKeySet("{PGDN}", "down")

timer()

While 1
    ;;;;; DEBUG ;;;;; GUICtrlSetData($Label1, $time_c)
    $time_c = TimerDiff($time)
    $time_c = Round($time_c, 0)
    If $time_c >= 1000 Then
        GUISetState(@SW_HIDE)
    EndIf
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

    EndSwitch
WEnd

Func timer()
    $time = TimerInit()
EndFunc

Func up()
    $cVol = GUICtrlRead($Progress1)
    SoundSetWaveVolume($cVol + 5)
    GUICtrlSetData($Label1, "Volume: " & $cVol + 5)
    GUISetState(@SW_SHOW)
    
EndFunc
IE Dev ToolbarMSDN: InternetExplorer ObjectMSDN: HTML/DHTML Reference Guide[quote]It is surprising what a man can do when he has to, and how little most men will do when they don't have to. - Walter Linn[/quote]--------------------[font="Franklin Gothic Medium"]Post a reproducer with less than 100 lines of code.[/font]
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...