Loop time with increment of 5min

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
johnhill
Posts: 24
Joined: 25 Sep 2014, 18:46

Loop time with increment of 5min

20 Jul 2015, 04:05

Hi,

I have below code that I would like to do loop with increment of 5min to avoid a long list. The target_time is the part that need 5min increment.

Code: Select all

target_time = 1100
target = %A_YYYY%%A_MM%%A_DD%%target_time%00
EnvSub, target, %A_Now%, Seconds
Sleep, % target * 1000 + 25000 ; milliseconds + delay 
johnhill
Posts: 24
Joined: 25 Sep 2014, 18:46

Re: Loop time with increment of 5min

20 Jul 2015, 05:27

Am I asking question that is easy to figure out or hard to figure out?
User avatar
Blackholyman
Posts: 1293
Joined: 29 Sep 2013, 22:57
Location: Denmark
Contact:

Re: Loop time with increment of 5min

20 Jul 2015, 06:31

Im not really sure what your asking for

if i run your script modified like this

Code: Select all

target_time = 1100
target = %A_YYYY%%A_MM%%A_DD%%target_time%00
EnvSub, target, %A_Now%, Seconds
sum := target * 1000 + 25000 ; milliseconds + delay 
msgbox,,, % sum
I get a negative number ( don't think you can sleep negatively )

please try and reword what you're trying to do...
Also check out:
Courses on AutoHotkey

My Autohotkey Blog
:dance:
just me
Posts: 9504
Joined: 02 Oct 2013, 08:51
Location: Germany

Re: Loop time with increment of 5min

20 Jul 2015, 07:17

Maybe? I'm not sure what you're after:

Code: Select all

#NoEnv
target_time = 1100
; for testing
target_time = %A_Now% ; current date-time
EnvAdd, target_time, 5, Minutes ; add 5 minutes
StringMid, target_time, target_time, 9, 4 ; get the HH24MI part of the date-time stamp
; end of test code
target = %A_YYYY%%A_MM%%A_DD%%target_time%00
Loop
{
   loop_target = %target%
   StringMid, loop_time, loop_target, 9, 4 ; for testing (see above)
   EnvSub, loop_target, %A_Now%, Seconds
   If loop_target <= 0
      break
   sleep_time := loop_target * 1000 + 25000 ; milliseconds + delay
   ToolTip, loop_time:`n%loop_time%`nloop_target:`n%loop_target%`nsleep_time:`n%sleep_time% ; for testing
   Sleep, %sleep_time%
   ; ... do what you want after the sleep
   EnvAdd, target, 5, Minutes
}
MsgBox, Exit!
johnhill
Posts: 24
Joined: 25 Sep 2014, 18:46

Re: Loop time with increment of 5min

20 Jul 2015, 20:59

Blackholyman wrote:Im not really sure what your asking for

if i run your script modified like this

Code: Select all

target_time = 1100
target = %A_YYYY%%A_MM%%A_DD%%target_time%00
EnvSub, target, %A_Now%, Seconds
sum := target * 1000 + 25000 ; milliseconds + delay 
msgbox,,, % sum
I get a negative number ( don't think you can sleep negatively )

please try and reword what you're trying to do...
If you run the script before 1100 as stated in target_time, it would result in negative.

I want to shorten my script by using loop. But have no knowledge of looping time by every 5 minutes.

Example part of my current script

Code: Select all

CountSleep:
target = %A_YYYY%%A_MM%%A_DD%%target_time%00
EnvSub, target, %A_Now%, Seconds
Sleep, % target * 1000 + 25000 ; milliseconds + delay
return

targer_time = 1100
GoSub CountSleep 
my task macro

targer_time = 1105
GoSub CountSleep 
my task macro

targer_time = 1110
GoSub CountSleep 
my task macro

targer_time = 1115
GoSub CountSleep
my task macro
johnhill
Posts: 24
Joined: 25 Sep 2014, 18:46

Re: Loop time with increment of 5min

20 Jul 2015, 23:26

just me wrote:Maybe? I'm not sure what you're after:

Code: Select all

#NoEnv
target_time = 1100
; for testing
target_time = %A_Now% ; current date-time
EnvAdd, target_time, 5, Minutes ; add 5 minutes
StringMid, target_time, target_time, 9, 4 ; get the HH24MI part of the date-time stamp
; end of test code
target = %A_YYYY%%A_MM%%A_DD%%target_time%00
Loop
{
   loop_target = %target%
   StringMid, loop_time, loop_target, 9, 4 ; for testing (see above)
   EnvSub, loop_target, %A_Now%, Seconds
   If loop_target <= 0
      break
   sleep_time := loop_target * 1000 + 25000 ; milliseconds + delay
   ToolTip, loop_time:`n%loop_time%`nloop_target:`n%loop_target%`nsleep_time:`n%sleep_time% ; for testing
   Sleep, %sleep_time%
   ; ... do what you want after the sleep
   EnvAdd, target, 5, Minutes
}
MsgBox, Exit!
Thank you for your help. Although I didn't understand your code well, your code did provide me with a solution. I tested with 1 minute and added msgbox after %sleep_time%. It is good. I like in fact you added the tooltip. It really help me to track where the code is running.

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 109 guests