Count time spent in a repeat cycle.

Hints, tips and tricks for newbies

Moderators: Dorian (MJT support), JRL

Post Reply
shapowsky
Newbie
Posts: 11
Joined: Sun Mar 06, 2016 9:29 am

Count time spent in a repeat cycle.

Post by shapowsky » Fri Jun 03, 2016 7:47 pm

There is a way to do this?
I need repeat a proccess in every 40 minutes, but i don't have the exactly total time spent in my repeat cycles.

I need something like this:

let>loopTime=0
let>totalTime=0
let>x=0

label>start

repeat>x
count_time_function
actions
let>x=x+1
count_time_function_end,%loopTime%
let>totalTime=totaTime+loopTime
until>x=5

wait>2400-totalTime
goto>start

Thanks in advance.

hagchr
Automation Wizard
Posts: 331
Joined: Mon Jul 05, 2010 7:53 am
Location: Stockholm, Sweden

Re: Count time spent in a repeat cycle.

Post by hagchr » Fri Jun 03, 2016 9:04 pm

Hi, If I understand it correctly then you want to loop 5 times and than wait until 40 minutes have passed since the process started, and then start again? In that case you do not have to keep track of the time in each loop, just the time since the process started (I assume the 5 loops finish within the 40 minutes so there is no running conflict).

Under the tab "Run When" you can set your script to run every 40 minutes, which would be a simple solution.

If you want to do it in the script like you tried to, then there are many possibilities, one example would be something like the example below. To define when it should stop then you can eg use Timer> which gives the time since the script started, or add a counter for total number of iterations, or GetTime> for current time.

Hope it helps.

Code: Select all

Let>timeDiff=0

//Intervall in minutes
Let>timeIntervall=40

Label>start
Timer>t1

let>x=0
label>start
repeat>x
 //your actions
 Let>x=x+1
until>x=5

While>timeDiff<{%timeIntervall%*60*1000}
    Timer>t2
    Let>timeDiff=%t2%-%t1%
    Wait>0.1
EndWhile

Let>timeDiff=0
Goto>start

shapowsky
Newbie
Posts: 11
Joined: Sun Mar 06, 2016 9:29 am

Re: Count time spent in a repeat cycle.

Post by shapowsky » Wed Jun 08, 2016 4:06 pm

Hello!
Sorry for the delay to post here.

Works fine in my project!

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts