Jump to content

[Solved] Timer problem


hcI
 Share

Recommended Posts

Hello everyone !

I'm making a little program who remind you every 2h to make a pause but i have a serious problem :

The timer don't start from 0. It start from a weird value : 131XXXX when X is my timer and 131 increase with my timer and when i close my app and i start it again, the 131 still here and if i close the app with, for exemple 135XXXX, when i re-launch it it's not 131 but 135... Like if the first 3 weird number were saved..

Here's my code, you might not understand the sentence because it's in french :P

Spoiler
MsgBox(262144,"WorkOnScreen","L'application a bien été lancée")
Opt("TrayMenuMode", 3)
Dim $trQuit = TrayCreateItem("Quitter")
TraySetIcon("WorkOnScreen_white.ico")
Dim $chrono_time = TimerInit()
Dim $msgAnswer

While 1
    Switch TrayGetMsg()
        Case $trQuit
            $msgAnswer = MsgBox(262180,"WorkOnScreen","Êtes-vous sûr de vouloir quitter l'application ?")
            If $msgAnswer = 6 Then Exit
    EndSwitch
    If $chrono_time = 7200000 Then
        MsgBox(262192,"WorkOnScreen","Attention vous avez passé 2 heures sur l'ordinateur !" & @CRLF & "Pensez  à faire une pause.")
        $chrono_time = TimerInit()
    EndIf
WEnd

 

Also, my program have a tray menu to close itself.

If someone know why it's doing this..

Edited by hcI
Topic solved
Link to comment
Share on other sites

Try this...

Opt("TrayMenuMode", 3)
Opt("TrayOnEventMode", 1)

Local $trQuit = TrayCreateItem("Quitter")
TraySetIcon("WorkOnScreen_white.ico")
TrayItemSetOnEvent($trQuit, "Quit")

;~ AdlibRegister("Alert", 7200000) ; 2 hours
AdlibRegister("Alert", 15000) ; 1000 miliseconds * 15 = 15 seconds

While Sleep(15) ; delay 15 miliseconds to prevent high cpu use
WEnd

Func Alert()
    MsgBox(262192,"WorkOnScreen","Attention vous avez passé 2 heures sur l'ordinateur !" & @CRLF & "Pensez  à faire une pause.", 5)
EndFunc

Func OnExit()
    AdlibUnRegister("Alert")
EndFunc

Func Quit()
    Exit
EndFunc

 

Edited by Luigi

Visit my repository

Link to comment
Share on other sites

#include <GuiConstantsEx.au3>
$timer = 0
$timer_len = 1000 * 5; 5 seconds

$hGui = guicreate("", 320, 200)
guisetstate()
do
    $msg = guigetmsg()
    if timerdiff($timer) > $timer_len then
        beep()
        $timer = timerinit(); restart the timer
    endif
until $msg = $gui_event_close

5 second beep timer

Edited by Xandy
Link to comment
Share on other sites

1 minute ago, Xandy said:

Yeah because TimerInit() returns a timestamp (I think) which is different from a timer length integer.

Oh okay thanks now i undertstand

Thanks you again guys !

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...