Countup Counter

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Countup Counter

24 May 2014, 02:24

i have this countdown counter (from another thread) that counts down or backward as designed (in this case, starts from 3 minutes and counts down to 0). what i would like to do is to reverse the process so that it counts up or forward from 0 (NOT from %A_Now%) to 3 minutes. i spent some time and couldn't make the necessary changes to the existing code, but i have this feeling that only a few slight, surgical changes are called for somewhere within this working code to do the trick!: :lol: :ugeek:

Code: Select all

; http://www.autohotkey.com/community/viewtopic.php?f=2&t=62008

#SingleInstance FORCE

XI = %A_ScreenWidth%
YI = %A_ScreenHeight%

XPos := XI/2
YPOs := YI/2
Message = "Log download complete"

XInput := XI-250
YInput := YI-150
; On-screen display (OSD)

CustomColor = 99AA55 ; C0C0C0 ; Can be any RGB color (it will be made transparent below):
Menu ,Tray, NoStandard
;Menu ,Tray, Add
Menu,Tray, Add,
Menu,Tray, Add, Exit, GuiClose
Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
Gui, Color, %CustomColor%
Gui, Font, s10
;Gui Add , Text , x0 y10 w130 h15 vpercent +Center, Time Elapsed %perc%`%
Gui Add , Progress , x5 y30 w120 h10 cRed vmyprogress
Gui, Font, s16
Gui, Add, Text, x5 w120 vMyTime cRed +Center, -00:00:00
WinSet, TransColor, %CustomColor% 175 ; Make all pixels of this color transparent and make the text itself translucent (150):
/*
SetTimer, UpdateOSD, 200 ; Causes a subroutine to be launched automatically and repeatedly at a specified time interval.
Gui, Show, x%XPos% y%YPos% w130 NoActivate, Script_Running ; NoActivate avoids deactivating the currently active window.
Return ; // End of Auto-Execute Section
*/

Loop, 1 ; 3
{
   ; MsgBox, Iteration number is %A_Index%. ; A_Index will be 1, 2, then 3
   Sleep, 100 ; 1000

   SetTimer, UpdateOSD, 200 ; Causes a subroutine to be launched automatically and repeatedly at a specified time interval.
   Gui, Show, x%XPos% y%YPos% w130 NoActivate, Script_Running ; NoActivate avoids deactivating the currently active window.

   Gui +LastFound +AlwaysOnTop +Caption +ToolWindow +OwnDialogs
   WinGetPos ,XPos ,YPos,,,Progress,
   ;Period = 00000025 ; Specified a known static Period (25 seconds)
   ;Period = 00000100 ; Specified a known static Period (1 minute) <<<<<<<<<<<<< 1 min
   Period = 00000300 ; Specified a known static Period (3 minutes) <<<<<<<<<<<<< 3 min
   StringMid ,PeriodD, Period,1, 2
   StringMid ,PeriodH, Period,3, 2
   StringMid ,Periodm, Period,5, 2
   StringMid ,Periods, Period,7, 2
   Periodsec := (PeriodD*86400)+(PeriodH*3600)+(Periodm*60)+Periods
   StartTime = %A_Now%
   ;EndTime = %A_Now%
   ;EndTime = 20121021181050
   EnvAdd EndTime, Periodsec, seconds
   EnvSub StartTime, EndTime, seconds
   StartTime := Abs(StartTime)

   perc := 0 ; Resets percentage to 0, otherwise this loop never sees the counter reset
   Loop
   {
       if perc = 100
           break ; Terminate the loop
       else
           continue ; Skip the below and start a new iteration
   }
    Gui, Cancel
    ExitApp
}

UpdateOSD:
mysec := EndTime
EnvSub, mysec, %A_Now%, seconds
GuiControl,, MyTime, % FormatSeconds( mysec )
perc := ((StartTime-mysec)/StartTime)*100
;MsgBox %StartTime%
perc := Floor(perc)
;MsgBox %perc%
GuiControl ,,myprogress,%perc%
;GuiControl ,,percent, Time Elapsed %perc%`%
If (perc=100){
    SetTimer, UpdateOSD, Off
    GuiControl ,,percent, Done %perc% `%
    Gui, Cancel
    }
Return

GuiClose: ; writes the settings into a ini file to get the position and continue count from last point (for long periods, endtimes where you had to shutdown the computer)
ExitApp

FormatSeconds(NumberOfSeconds) ; Convert the specified number of seconds to hh:mm:ss format
{
    time = 19990101 ; *Midnight* of an arbitrary date.
    time += %NumberOfSeconds%, seconds
    FormatTime, mmss, %time%, mm:ss
    hours := NumberOfSeconds // 3600 ; This method is used to support more than 24 hours worth of sections
    hours := hours < 10 ? "0" . hours : hours
    return hours ":" mmss
}
Last edited by Guest10 on 26 May 2014, 09:33, edited 4 times in total.
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Changing Countdown Counter to Count Up Instead of Down

24 May 2014, 17:27

2 new lines added and 1 existing line modified and that did the trick! :lol: :ugeek:
kiwichick
Posts: 169
Joined: 21 Jan 2014, 22:03

Re: Changing Countdown Counter to Count Up Instead of Down

24 May 2014, 23:06

Hi there, Would you mind posting your amended script. I would love a count-up timer too :-)
Guest10
Posts: 578
Joined: 01 Oct 2013, 02:50

Re: Changing Countdown Counter to Count Up Instead of Down

25 May 2014, 03:45

hi, kiwichick! the original author wrote this script out of boredom (*). however, i found serious applications for it. i will post the amended version shortly. in the meantime, i would like to see what other bored ( :lol: ) members can come up with by way of creative solutions. :lol: :ugeek:

(*) quote: "recently, I'm having a lot of free time while on work. so I keep looking at my watch and calculate how much longer I have to stay there before I go home. Therefore, I searched a few older treads on Countdown timers and this is the result. hope you like it!"

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: apeironn, Google [Bot], madensuyu1, peter_ahk and 336 guests