Stop a macro
Moderators: Dorian (MJT support), JRL
Stop a macro
Hi everyone!
Is there any way to stop a running macro if its normal execution time is exceeded? For instance, I've programmed a macro which scrolls down a web page until an image is found. If that image never shows, the macro will never exit the loop. A counter in the loop is not a suitable solution for what I need. Once I found a macro running for more than 2 hours and I'd want to avoid this.
Any help, please?
Thank you!
Is there any way to stop a running macro if its normal execution time is exceeded? For instance, I've programmed a macro which scrolls down a web page until an image is found. If that image never shows, the macro will never exit the loop. A counter in the loop is not a suitable solution for what I need. Once I found a macro running for more than 2 hours and I'd want to avoid this.
Any help, please?
Thank you!
-
- Newbie
- Posts: 18
- Joined: Thu Mar 25, 2010 11:00 am
- Location: Vancouver
Hope this helps. Just remove the MDL> and place your script there.
It will then allow the script to loop only as many times as determined by the until> value.
although it is a counter, It may still work just time how long your single loop is. If running your script loop for finding the image takes only 5 seconds, then its a simple 5:1 seconds to timeout ratio and if you want it to time out after 2 minutes you would change Until>TO,24
It will then allow the script to loop only as many times as determined by the until> value.
although it is a counter, It may still work just time how long your single loop is. If running your script loop for finding the image takes only 5 seconds, then its a simple 5:1 seconds to timeout ratio and if you want it to time out after 2 minutes you would change Until>TO,24
Code: Select all
Let>TO=0
Repeat>TO
Add>TO,1
\\Script here
MDL>Just change Until>TO, to however many loops you want %TO%
Until>TO,5
Hi Jeff!
I've followed your instructions blindly and it seems to be working.
Anyway I still don't understand why, I don't understand what the structure you suggested is doing in my script. Could you please explain it to me? I want to understand it well just in case I need to use something similar in the future.
Thank you for your time.
I've followed your instructions blindly and it seems to be working.
Anyway I still don't understand why, I don't understand what the structure you suggested is doing in my script. Could you please explain it to me? I want to understand it well just in case I need to use something similar in the future.
Thank you for your time.
-
- Newbie
- Posts: 18
- Joined: Thu Mar 25, 2010 11:00 am
- Location: Vancouver
I don't fully understand it all myself as I'm still rather new to using MS.
But this is how this one is working.
Let>TO=0 assigns the numeric value of the word TO to equal 0 *can be changed to anything I selected TO as an abbreviation of TimeOut*
Repeat>TO shows where to continue the script if the until value is not reached
the Add>TO,1 means simply every time the script passes this code it will add +1 to the value of TO. So on every loop it goes 0,1,2,3,4, Etc.
Until>TO,5 takes you back to Repeat>TO unless the TO value equals 5, or whatever you have it set to.
So as long as you have the script after the Add but before the until it will repeat that section as many times Until the value becomes true.
If you have it searching for an img you could insert something like
IF>img=1
goto>image found
then after the looping have make a Label>image found
and put the rest of the script that happens after that image is found. it will quickly and easily get you out of the loop when the image is found.
Just a side thought if not already done, under Until add and Exit code or an error dialog that way when it times out it will bring up an error or instantly close the macro.
heres a quick example of what I mean with the if>img, the label, error message then exit.
Have fun tinkering around with the script and hope you get it all working properly and able to understand why and how its working.
But this is how this one is working.
Let>TO=0 assigns the numeric value of the word TO to equal 0 *can be changed to anything I selected TO as an abbreviation of TimeOut*
Repeat>TO shows where to continue the script if the until value is not reached
the Add>TO,1 means simply every time the script passes this code it will add +1 to the value of TO. So on every loop it goes 0,1,2,3,4, Etc.
Until>TO,5 takes you back to Repeat>TO unless the TO value equals 5, or whatever you have it set to.
So as long as you have the script after the Add but before the until it will repeat that section as many times Until the value becomes true.
If you have it searching for an img you could insert something like
IF>img=1
goto>image found
then after the looping have make a Label>image found
and put the rest of the script that happens after that image is found. it will quickly and easily get you out of the loop when the image is found.
Just a side thought if not already done, under Until add and Exit code or an error dialog that way when it times out it will bring up an error or instantly close the macro.
heres a quick example of what I mean with the if>img, the label, error message then exit.
Have fun tinkering around with the script and hope you get it all working properly and able to understand why and how its working.
Code: Select all
Let>TO=0
Repeat>TO
Add>TO,1
\\your script
IF>img=1
Goto>Img Found
EndIf
Until>TO,5
MDL>Image Not Found
Exit
Label>Img Found
\\Rest of your script when image is found
Thaks again for your answer.
Now I understand what you mean and I realize that what you suggested is a basic loop with a counter, which I have already been doing in my scripts.
Probably I didn't explain correctly what I needed to do. Let's start over.
In some of my scripts there must be some errors which I am still not able to find and sometimes the script doesn't pass the code entirely. So, sometimes I find my computer stuck while running a script and from the time I secheduled the macro I know it's been that way for hours and hours. My computer is then very hot and the "I am thinking" led flashes crazily.
Said so, what I need to do is, if my script is supposed to run entirely in, let's say, 10 seconds, if 2 minutes have passed and it still hasn't finished (which probably means it definitely won't) the computer should stop the macro.
It seems to me that it should be something in the code that counts the time passed since the macro started and, if it passes a limit value, it would stop the process no matter how far it's gone.
I'm sorry for my English, I just try to do my best.
Thanks Jeff.
Now I understand what you mean and I realize that what you suggested is a basic loop with a counter, which I have already been doing in my scripts.
Probably I didn't explain correctly what I needed to do. Let's start over.
In some of my scripts there must be some errors which I am still not able to find and sometimes the script doesn't pass the code entirely. So, sometimes I find my computer stuck while running a script and from the time I secheduled the macro I know it's been that way for hours and hours. My computer is then very hot and the "I am thinking" led flashes crazily.
Said so, what I need to do is, if my script is supposed to run entirely in, let's say, 10 seconds, if 2 minutes have passed and it still hasn't finished (which probably means it definitely won't) the computer should stop the macro.
It seems to me that it should be something in the code that counts the time passed since the macro started and, if it passes a limit value, it would stop the process no matter how far it's gone.
I'm sorry for my English, I just try to do my best.
Thanks Jeff.
-
- Newbie
- Posts: 18
- Joined: Thu Mar 25, 2010 11:00 am
- Location: Vancouver
If your script is constantly getting stuck in an infinite loop then there is something wrong with the script. Have you tried using the debugger and logs to find what is causing the problem?
you can try creating a WriteLn that will create and run a secondary script with a wait time for however long you want it to run for, after the wait time have it end the process which is running the main script. Since it would be on a secondary script it shouldn't be affected by any infinite loop problems.
I don't know enough about using WriteLn yet to be able to help, I can only tell you that it could be the next step to try... after debugging your script to ensure there isn't a small mistake somewhere of course.
you can try creating a WriteLn that will create and run a secondary script with a wait time for however long you want it to run for, after the wait time have it end the process which is running the main script. Since it would be on a secondary script it shouldn't be affected by any infinite loop problems.
I don't know enough about using WriteLn yet to be able to help, I can only tell you that it could be the next step to try... after debugging your script to ensure there isn't a small mistake somewhere of course.
-
- Newbie
- Posts: 18
- Joined: Thu Mar 25, 2010 11:00 am
- Location: Vancouver
Re: Stop a macro
@ JeffDaruecan
I believe you mean "WSI_TIMEDOUT" and not "WSI_TIMEOUT"
Jamie
I believe you mean "WSI_TIMEDOUT" and not "WSI_TIMEOUT"
Jamie