Jump to content

Create 24h timer


Terenz
 Share

Recommended Posts

A friend of mine ask me to make a 24h timer for check how long require some task on his PC. I'll do it my friend, i'm a super expert of this things! B)

In my mind was easy but seems a timer has a "couple" of rules.

$sHour = 23
$sMin = 57
$sSec = @SEC

$sHour = StringFormat("%02s", $sHour)
$sMin = StringFormat("%02s", $sMin)

Do
    If $sSec <> @SEC Then
        $sSec = @SEC
        Select
;~          Case $sSec = "00" And $sMin = "59"
;~              $sHour += 1
;~              $sMin = 0
;~              If $sMin < 10 Then $sMin = StringFormat("%02s", $sMin)
;~              If $sHour < 10 Then $sHour = StringFormat("%02s", $sHour)
            Case $sSec = "00" And Not $sMin = "59"
                $sMin += 1
                If $sMin < 10 Then $sMin = StringFormat("%02s", $sMin)
;~          Case $sHour = "23" And $sMin = "00" And $sSec = "00"
;~              $sHour = 0
;~              StringFormat("%02s", $sHour)
        EndSelect
        ConsoleWrite($sHour & ":" & $sMin & ":" & $sSec & @CRLF)
    EndIf
Until 0

Well 'im stuck, that things doesn't satisfy me and not work. Example i don't know how to start again from 00:00:00. If i'll check 23:59:59 i'll update the hour one second early, if i'll check 23:00:00 can be two different time 23:00:00 and 00:00:00

Thanks for help me to resolve that code.

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

What about

$sHour = 23
$sMin = 59
$SecsPassed = 55
; obviously set all above to 0
$sSec = 60


Do
    If $sSec <> @SEC Then
        $sSec = @SEC
        $SecsPassed += 1
        If $SecsPassed > 59 Then
            $SecsPassed = 0
            $sMin += 1
            If $sMin > 59 Then
                $sHour += 1
            EndIf
        EndIf
        if $sHour > 23 Then $sHour = 0
        if $sMin > 59 Then $sMin = 0
        ConsoleWrite(StringFormat("%02s", $sHour) & ":" & StringFormat("%02s", $sMin) & ":" & StringFormat("%02s", $SecsPassed) & @CRLF)
    EndIf

    Sleep(10)

Until 0

 

AutoIt Absolute Beginners    Require a serial    Pause Script    Video Tutorials by Morthawt   ipify 

Monkey's are, like, natures humans.

Link to comment
Share on other sites

and what about

$hour = 23
$min = 59
$sec = 55
; obviously set all above to 0
Global $ticks = $hour*3600 + $min*60 + $sec

AdlibRegister("_Display", 1000)
While 1
  Sleep(10)
Wend

Func _Display()
  Local $sc, $mn, $hr
  $sc = Mod($ticks, 60)
  $mn = Mod($ticks/60, 60)
  $hr = Mod($ticks/3600, 24)
  $str = StringFormat("%02i", $hr) & ":" & StringFormat("%02i", $mn) & ":" & StringFormat("%02i", $sc)
  Tooltip($str, 0, 0)
  $ticks += 1
EndFunc

:)

Link to comment
Share on other sites

@mikell: your StringFormat line can be shorten to:

$str = StringFormat("%02i:%02i:%02i", $hr, $mn, $sc)

^_^

Please don't send me any personal message and ask for support! I will not reply!

Selection of finest graphical examples at Codepen.io

The own fart smells best!
Her 'sikim hıyar' diyene bir avuç tuz alıp koşma!
¯\_(ツ)_/¯  ٩(●̮̮̃•̃)۶ ٩(-̮̮̃-̃)۶ૐ

Link to comment
Share on other sites

Correct me if i'm wrong, but i think AdlibRegister is unnecessary. It call the function every second, is the same inside the loop since we check for @SEC? Considered a loop is required for the script to be alive, put everything there isn't better and we saving an Adlib? Just my curiosity, both script work fine for what i have see

Edited by Terenz

Nothing is so strong as gentleness. Nothing is so gentle as real strength

 

Link to comment
Share on other sites

@Terenz in which way do you think to use the timer to "check how long require some task on his PC"?

edit:

????

Local $iDelay = 0
Local $timer = 86390 ; start timer at 23:59:50 as example

While True
    Do
        If $iDelay <> @SEC Then
            $iDelay = @SEC
            ConsoleWrite(StringFormat("%02d:%02d:%02d", Floor($timer / 3600), Mod(Floor($timer / 60), 60), Mod($timer, 60)) & @CRLF)
            $timer += 1
        EndIf
    Until $timer = 86400 ; total seconds in 24 Hours
    $timer = 0 ; reset timer
WEnd

 

Edited by Chimp

 

image.jpeg.9f1a974c98e9f77d824b358729b089b0.jpeg Chimp

small minds discuss people average minds discuss events great minds discuss ideas.... and use AutoIt....

Link to comment
Share on other sites

  • 2 weeks later...

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