Jump to content
Sign in to follow this  
ondrajka

Countdown Timer

Recommended Posts

ondrajka

Here is my countdown timer that will also count up after it reaches zero. Was wondering how to do autoit math with remainders and non base 10 numbers. This was my test project just to see if it could be done.

#include <Date.au3>
  
  $u=0; loop until
  $date = _DateAdd( 's',864015, _NowCalc()) 
  $time = InputBox("Target Date", "Default 10 Days 15 Seconds" & @CRLF & "YYYY/MM/DD HH:MM:SS", $date)
  
  
  Do
      Sleep(1000)
  
      $td = _DateDiff('s', _NowCalc(), $time)
      
      $late = ""; dummy neg no
      If $td < 0 Then $late = "-"; dummy neg yes
      If $td < 0 Then $td = -$td; convert neg $td to pos for math
  
      $d = 0; Days with remainder math
      If $td > 86400 Then
          $dm = $td
          Do
              $dm = $dm - 86400
              $d = $d + 1
          Until $dm < 86400
      EndIf
  
      $h = 0; Hours with remainder math
      If $td - ($d * 86400) > 3600 Then
          $hm = $td - ($d * 86400)
          Do
              $hm = $hm - 3600
              $h = $h + 1
          Until $hm < 3600
      EndIf
  
      $m = 0; Miutes with remainder math
      If $td - ($d * 86400) - ($h * 3600) > 60 Then
          $mm = $td - ($d * 86400) - ($h * 3600)
          Do
              $mm = $mm - 60
              $m = $m + 1
          Until $mm < 60
      EndIf
  
      $s = $td - ($d * 86400) - ($h * 3600) - ($m * 60); Seconds
  
      $db = ""; non zero for 2 digit numbers
      $hb = ""
      $mb = ""
      $sb = ""
  
      If $d < 10 Then $db = 0; zero for 1 digit number
      If $h < 10 Then $hb = 0
      If $m < 10 Then $mb = 0
      If $s < 10 Then $sb = 0
  
       ToolTip("Target Date  " & $time & @CRLF & "Time Left     " & $late & $db & $d & ":" & $hb & $h & ":"  & $mb & $m & ":" & $sb & $s, 10, 10)
  
  Until $u = 1

Share this post


Link to post
Share on other sites
Yashied

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
Sign in to follow this  

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.