Jump to content
Macro Express Forums

Repeat For 10 Minutes


Recommended Posts

Seems simple enough, but can't figure it out.

 

Want macro portion to repeat.  For 10 minutes.  Repeat Until... 10 minutes passes.  End Repeat.

 

Note that I am not asking MEP to sit around doing nothing for 10 minutes, waiting, and then whatever.  I am asking MEP to run a macro, however many times, up until 10 minutes goes by.  Then move on to whatever's next.  After that 10 minutes of macro running.

 

So, MEP, keep an eye on the clock.  Do the macro portion.  Lots and lots of times, if possible.  For 10 minutes.  Macro portion a bunch of times.  Yeah.  Good.  So easy, huh.

 

Who here knows the answer?

 

Please??

 

Thanks,

Nicholas Kormanik

 

 

Link to comment
Share on other sites

I think Wait For Time to Elapse is pretty accurate.  Before starting the repeat loop in the primary macro, set some flag, like maybe store zero in an environment variable.  Then start a second macro which does the Wait For Time, and changes the variable from zero to one at the end of the delay.  In the primary macro's repeat loop, check the variable and exit from the repeat loop when it becomes one rather than zero.  You can check the variable every time through the loop, or every tenth time or hundredth time or thousandth time depending on the precision you want and how rapidly the repeated code executes. 

 

Make sure the two macros are allowed to run simultaneously. 

 

You can check how accurate the Wait is with a simple two-line macro, comparing to a wall clock or stop watch or whatever:

//  
Wait Time Elapse: 0 Minutes 22 Seconds
Text Box Display: time over
// 

Link to comment
Share on other sites

1 hour ago, acantor said:

Macro Express executes repeat loops astonishingly quickly.

I think it's a good idea to embed a time delay within almost every loop.  If the macro is watching for a screen change, I usually use a 100ms delay -- 1/10 of a second -- on each pass through the loop.  That provides almost instant response in terms of human perception.  It also makes it easy to specify how long the repeat loop will run.  For example, if you want it to keep repeating for 10 minutes, then 600 repeats with 1-second delays will in theory accomplish that.  Or 6,000 repeats with 1/10-second delays.  When quick response is not an issue, I have macros that wait 10 or 15 seconds during each repeat.  A repeat loop with no embedded delays can eat up a lot of processor power for no particular benefit. 

Link to comment
Share on other sites

What I often do is make a text box that gets updated and have a 1 second delay so the loop updates the text box every second. When I start, I set a time variable for the desired time in the future. In your case, value a time variable for now then add 10 minutes to it. In the loop, update another time variable with the current time every iteration and compare to the target end time. Then when %Now% is greater than %EndTime%, exit the loop. This method is best if what happens in the loop is time consuming and can vary. 

But most times I calculate it. 1 second delays and how ever many seconds I need, loop that many times. 600 in this case. There is some time for the macro running, but it's usually minimal and only adds a second or two at the end. And if it's predictable, I'll measure the time it take to iterate 600 times, subtract 10 minutes, and subtract the number of iterations. But this can vary from machine to machine and depending on what the macro is doing. It just depends. If I just want something "about 10 minutes". then this is the quick and dirty way to do it. 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...