ArkiePazi

Countdown to some fixed clock period

5 posts in this topic

Hi, I am have build a program that notefies me at fixed hours. Like so:

06:00

10:00

20:00

etc...

Everything works fine but I would like to have a countdown. It must also work from 23:00 to 01:00. I have run into problems here. I need this to work every day so setting a date is not going to work.

Do you have any sugestions/questions?

I can write a litle example of what i got if that is any help, but i doupt that.

Thank you in advance.

Share this post


Link to post
Share on other sites



i do, convert date to seconds with destination date to seconds, compare countdown untill 0, every time when it hit 0 set counter variable to new current date

and yes a little example whud b nice


TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

Thank you for your answer. Sadly I did not entierly understand. If you could provide an example I would be very greatfull. I have written a litle example of what i got so far. I thought a focused example would be easier to read than my full script. It should contain the main features.

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
GUICreate("Form1", 155, 91, 192, 131)
$Label1 = GUICtrlCreateLabel("00:00:00", 80, 32, 60, 17)
$Label2 = GUICtrlCreateLabel("Next Time:", 16, 32, 52, 17)
$Label3 = GUICtrlCreateLabel("Time Now:", 16, 8, 52, 17)
$Label4 = GUICtrlCreateLabel("00:00:00", 80, 8, 60, 17)
$Label5 = GUICtrlCreateLabel("Time Left:", 16, 56, 52, 17)
$Label6 = GUICtrlCreateLabel("00:00:00", 80, 56, 60, 17)
GUISetState(@SW_SHOW)
$Htime = @HOUR
$Mtime = @MIN
$Stime = @SEC
_Clock()
_NextReset()

While 1
    $1sec1 = @SEC
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit

EndSwitch
$1sec2 = @SEC
If $1sec2 > $1sec1 Then
    _Clock()
    _NextReset()
EndIf
WEnd

Func _Clock ()
    $Htime = @HOUR
    $Mtime = @MIN
    $Stime = @SEC
    GUICtrlSetData($Label4,$Htime & ":" & $Mtime & ":" & $Stime)
EndFunc

Func _NextReset()
    If $Htime = 22 or $Htime = 23 or $Htime = 00 or $Htime = 01 Then
        GUICtrlSetData($Label1,"02" & ":" & "00" & ":" & "00")
        If $Stime = 01 Then
            MsgBox(0,"Example","The clock is now 22:00")
        EndIf
    EndIf
    If $Htime = 02 or $Htime = 03 or $Htime = 04 or $Htime = 05 Then
        GUICtrlSetData($Label1,"06" & ":" & "00" & ":" & "00")
        If $Stime = 01 Then
            MsgBox(0,"Example","The clock is now 02:00")
        EndIf
    EndIf
    If $Htime = 06 or $Htime = 07 or $Htime = 08 or $Htime = 09 Then
        GUICtrlSetData($Label1,"10" & ":" & "00" & ":" & "00")
        If $Stime = 01 Then
            MsgBox(0,"Example","The clock is now 06:00")
        EndIf
    EndIf
    If $Htime = 10 or $Htime = 11 or $Htime = 12 or $Htime = 13 Then
        GUICtrlSetData($Label1,"14" & ":" & "00" & ":" & "00")
        If $Stime = 01 Then
            MsgBox(0,"Example","The clock is now 10:00")
        EndIf
    EndIf
    If $Htime = 14 or $Htime = 15 or $Htime = 16 or $Htime = 17 Then
        GUICtrlSetData($Label1,"18" & ":" & "00" & ":" & "00")
        If $Stime = 01 Then
            MsgBox(0,"Example","The clock is now 14:00")
        EndIf
    EndIf
    If $Htime = 18 or $Htime = 19 or $Htime = 20 or $Htime = 21 Then
        GUICtrlSetData($Label1,"22" & ":" & "00" & ":" & "00")
        If $Stime = 01 Then
            MsgBox(0,"Example","The clock is now 18:00")
        EndIf
    EndIf
EndFunc

Thank you again, I will read yor post a few time more and see if I can understand better.

Share this post


Link to post
Share on other sites

you can play with it something like this

(hope that i did not make mistake whele playing with it)

#Include <Date.au3>

Global $h, $m ,$s
Global $YY=@YEAR, $MM=@MON, $DD=@MDAY


;----------------------------
$alarm = '16:15:00'
;----------------------------


$split = StringSplit($alarm,":")
If _TimeToTicks(@HOUR,@MIN,@SEC) > _TimeToTicks($split[1],$split[2],$split[3])  Then
    $sJulDate = _DateToDayValue (@YEAR, @MON, @MDAY)
    _DayValueToDate ($sJulDate+1, $YY, $MM, $DD)
EndIf
While 1
    $timeuntill = StringReplace(_DateDiff( 's',$YY&'/'&$MM&'/'&$DD&' '&$alarm,_NowCalc()),"-","")*1000
    _TicksToTime($timeuntill, $h,$m,$s)
    ToolTip($h&":"&$m&":"&$s)
    If $h+$m+$s = "0" Then
        MsgBox(0,"alarm Msgbox","alarm!!!!!!!!!!!!!!!",2)
        $sJulDate = _DateToDayValue (@YEAR, @MON, @MDAY)
        _DayValueToDate ($sJulDate+1, $YY, $MM, $DD)
    EndIf
WEnd

TCP server and client - Learning about TCP servers and clients connection
Au3 oIrrlicht - Irrlicht project
Au3impact - Another 3D DLL game engine for autoit. (3impact 3Drad related)



460px-Thief-4-temp-banner.jpg
There are those that believe that the perfect heist lies in the preparation.
Some say that it’s all in the timing, seizing the right opportunity. Others even say it’s the ability to leave no trace behind, be a ghost.

 

Share this post


Link to post
Share on other sites

Thank you so much. I got it working with help of your example. This is the new example with multiple fix points and multiple notifications (for the googlers out there).

#include <GUIConstantsEx.au3>
#include <StaticConstants.au3>
#include <WindowsConstants.au3>
#Include <Date.au3>
GUICreate("Form1", 155, 91, 192, 131)
$Label1 = GUICtrlCreateLabel("00:00:00", 80, 32, 60, 17)
$Label2 = GUICtrlCreateLabel("Next Time:", 16, 32, 52, 17)
$Label3 = GUICtrlCreateLabel("Time Now:", 16, 8, 52, 17)
$Label4 = GUICtrlCreateLabel("00:00:00", 80, 8, 60, 17)
$Label5 = GUICtrlCreateLabel("Time Left:", 16, 56, 52, 17)
$Label6 = GUICtrlCreateLabel("00:00:00", 80, 56, 60, 17)
GUISetState(@SW_SHOW)
Global $h, $m ,$s
Global $YY=@YEAR, $MM=@MON, $DD=@MDAY

;----------------------------
$alarm1 = '02:00:00'
$alarm2 = '06:00:00'
$alarm3 = '10:00:00'
$alarm4 = '14:00:00'
$alarm5 = '18:00:00'
$alarm6 = '22:00:00'
;----------------------------

$split1 = StringSplit($alarm1,":")
$split2 = StringSplit($alarm2,":")
$split3 = StringSplit($alarm3,":")
$split4 = StringSplit($alarm4,":")
$split5 = StringSplit($alarm5,":")
$split6 = StringSplit($alarm6,":")

$Htime = @HOUR
$Mtime = @MIN
$Stime = @SEC
_Clock()
_NextReset()
_TimeLeft()
While 1
    $1sec1 = @SEC
    $nMsg = GUIGetMsg()
    Switch $nMsg
        Case $GUI_EVENT_CLOSE
            Exit
EndSwitch
$1sec2 = @SEC
If $1sec2 > $1sec1 Then
    _Clock()
    _TimeLeft()
    _NextReset()
    _Notify()
EndIf
WEnd

Func _Clock ()
    $Htime = @HOUR
    $Mtime = @MIN
    $Stime = @SEC
    GUICtrlSetData($Label4,$Htime & ":" & $Mtime & ":" & $Stime)
EndFunc

Func _TimeLeft()
    ;Chooses goal
    If _TimeToTicks(@HOUR,@MIN,@SEC) > _TimeToTicks($split1[1],$split1[2],$split1[3])  Then
        $alarm = $alarm2
    EndIf
    If _TimeToTicks(@HOUR,@MIN,@SEC) > _TimeToTicks($split2[1],$split2[2],$split2[3])  Then
        $alarm = $alarm3
    EndIf
    If _TimeToTicks(@HOUR,@MIN,@SEC) > _TimeToTicks($split3[1],$split3[2],$split3[3])  Then
        $alarm = $alarm4
    EndIf
    If _TimeToTicks(@HOUR,@MIN,@SEC) > _TimeToTicks($split4[1],$split4[2],$split4[3])  Then
        $alarm = $alarm5
    EndIf
    If _TimeToTicks(@HOUR,@MIN,@SEC) > _TimeToTicks($split5[1],$split5[2],$split5[3])  Then
        $alarm = $alarm6
    EndIf
    If _TimeToTicks(@HOUR,@MIN,@SEC) > _TimeToTicks($split6[1],$split6[2],$split6[3])  Then
        $sJulDate = _DateToDayValue (@YEAR, @MON, @MDAY)
        _DayValueToDate ($sJulDate+1, $YY, $MM, $DD)
        $alarm = $alarm1
    EndIf
    ; math out how long time left
    $timeuntill = StringReplace(_DateDiff( 's',$YY&'/'&$MM&'/'&$DD&' '&$alarm,_NowCalc()),"-","")*1000
    _TicksToTime($timeuntill, $h,$m,$s)
    ; prints it
    GUICtrlSetData($Label6,$h&":"&$m&":"&$s)
    ; When counter reach 0 do:
    If $h+$m+$s = "0" Then
        $sJulDate = _DateToDayValue (@YEAR, @MON, @MDAY)
        _DayValueToDate ($sJulDate+1, $YY, $MM, $DD)
    EndIf
EndFunc


Func _NextReset()
    If $Htime = 22 or $Htime = 23 or $Htime = 00 or $Htime = 01 Then
        GUICtrlSetData($Label1,"02" & ":" & "00" & ":" & "00")
    EndIf
    If $Htime = 02 or $Htime = 03 or $Htime = 04 or $Htime = 05 Then
        GUICtrlSetData($Label1,"06" & ":" & "00" & ":" & "00")
    EndIf
    If $Htime = 06 or $Htime = 07 or $Htime = 08 or $Htime = 09 Then
        GUICtrlSetData($Label1,"10" & ":" & "00" & ":" & "00")
    EndIf
    If $Htime = 10 or $Htime = 11 or $Htime = 12 or $Htime = 13 Then
        GUICtrlSetData($Label1,"14" & ":" & "00" & ":" & "00")
    EndIf
    If $Htime = 14 or $Htime = 15 or $Htime = 16 or $Htime = 17 Then
        GUICtrlSetData($Label1,"18" & ":" & "00" & ":" & "00")
    EndIf
    If $Htime = 18 or $Htime = 19 or $Htime = 20 or $Htime = 21 Then
        GUICtrlSetData($Label1,"22" & ":" & "00" & ":" & "00")
    EndIf
EndFunc

Func _Notify()
        If $Htime = 02 And $Mtime = 00 And $Stime = 01 Then
            TrayTip("Alarm!","Clock is 02",30)
        EndIf
        If $Htime = 06 And $Mtime = 00 And $Stime = 01 Then
            TrayTip("Alarm!","Clock is 06",30)
        EndIf
        If $Htime = 10 And $Mtime = 00 And $Stime = 01 Then
            TrayTip("Alarm!","Clock is 10",30)
        EndIf
        If $Htime = 14 And $Mtime = 00 And $Stime = 01 Then
            TrayTip("Alarm!","Clock is 14",30)
        EndIf
        If $Htime = 18 And $Mtime = 00 And $Stime = 01 Then
            TrayTip("Alarm!","Clock is 18",30)
        EndIf
        If $Htime = 22 And $Mtime = 00 And $Stime = 01 Then
            TrayTip("Alarm!","Clock is 22",30)
        EndIf
EndFunc

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