Jump to content

Simple Timer


 Share

Recommended Posts

Hello again guys!

My problem today is (which I encounter everyday :angry: (but always solve by myself)) a timer, that does x when the time has end.

By far I have this:

Func TimerRun()

   Local $Timer = 0
   Local $AllowTimer = 1
   If GUICtrlRead($checkboxRunTimer) = 1 And $AllowTimer = 1 Then
      While 1
         SelectTimerAmount() ; <- This is another Func
         $Timer+=1
         ToolTip($Timer)
         If $Timer == $MaximumTime Then
            $AllowTimer = 0
            $Timer = 0
            ToolTip("Time is up!")
            Sleep(2000)
            Exit
         EndIf
      WEnd
   EndIf

EndFunc

Okay, there is the function that "ticks" the Timer, now here is the GUI script:

$checkboxRunTimer = GUICtrlCreateCheckbox("Tick to set up Timer", 160, 216, 89, 17)
$comboSetTime = GUICtrlCreateCombo("", 468, 385, 89, 25, BitOR($CBS_DROPDOWNLIST,$CBS_AUTOHSCROLL))
GUICtrlSetData(-1, "30 seconds|1 min|2 min|3 min|5 min", "30 seconds") ;<- 30 seconds is default
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetBkColor(-1, 0x000000)

Global $MaximumTime

And finally, the list where you can choose your time:

Func SelectTimerAmount()
   Switch $comboSetTime
      Case "30 seconds"
         $MaximumTime = 30000 ;<- (Like Sleep(30000))
      Case "1 min"
         $MaximumTime = 60000
      Case "2 min"
         $MaximumTime = 120000
      Case "3 min"
         $MaximumTime = 180000
      Case "5 min"
         $MaximumTime = 300000
   EndSwitch
EndFunc

Oh and the While 1 script (runs 24/7)

If GUICtrlRead($checkboxRunTimer) = 1 Then
   TimerRun()
EndIf

 

Now to my problem. When I run the file, I will see tooltip written only "1" and then it tooltips "Time is up!" and exits.

I don't want it to immidiately exit, but to wait until the 30 seconds has passed (if you have chosen 30 seconds).

What am I doing wrong? :(

Thanks in advance!

 

EDIT: Wait what... now it works?

 

EDIT2: Now I found my solution.. I had comboSetTime and cSetTime (<- both are combo boxes) and cSetTime was only visible and the comboSetTime were hidden somewhere so of course it did not work because I never defined the amount or ticked the checkbox... Stupid me, anyways here is some kind of example for others if they need a timer :D

You can lock this topic!

Edited by Timppa
Link to comment
Share on other sites

Func TimerRun()

   Local $Timer = 0
   Local $AllowTimer = 1
   If GUICtrlRead($checkboxRunTimer) = 1 And $AllowTimer = 1 Then
      While 1
         SelectTimerAmount() ; <- This is another Func
         $Timer+=1
         ToolTip($Timer)
         If $Timer >= $MaximumTime Then; change this to >=
            $AllowTimer = 0
            $Timer = 0
            ToolTip("Time is up!")
            Sleep(2000)
            Exit
         EndIf
      WEnd
   EndIf

EndFunc

Dont use $timer += 1. Use timerinit and timerdiff functions. 

Get Scite to add a popup when you use a 3rd party UDF -> http://www.autoitscript.com/autoit3/scite/docs/SciTE4AutoIt3/user-calltip-manager.html

Link to comment
Share on other sites

Func TimerRun()

   Local $Timer = 0
   Local $AllowTimer = 1
   If GUICtrlRead($checkboxRunTimer) = 1 And $AllowTimer = 1 Then
      While 1
         SelectTimerAmount() ; <- This is another Func
         $Timer+=1
         ToolTip($Timer)
         If $Timer >= $MaximumTime Then; change this to >=
            $AllowTimer = 0
            $Timer = 0
            ToolTip("Time is up!")
            Sleep(2000)
            Exit
         EndIf
      WEnd
   EndIf

EndFunc

Dont use $timer += 1. Use timerinit and timerdiff functions. 

Why? Wouldn't $Timer+=1 work as well as TimerDiff and TimerInit?

Or is there some kind of difference that makes it faster to use them?

 

EDIT: 

If $Timer >= $MaximumTime Then; change this to >=

^ That doesn't matter. $Timer will be equal to $MaximumTime even though if it might go above the integer, but it doesn't matter because it should start to read next line.

Edited by Timppa
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...