Repeat-until loop does not work
Moderators: Dorian (MJT support), JRL
Repeat-until loop does not work
Hi,
I have this macro with two Repeat-Until loops. The strange thing about it is that one loop work fine, but the other not. For some reason it does not loop (it continues in the macro after executing the commands in the loop once). Does anyone have any idea why this second repeat-until loop does not work?
Here's (part of) the macro. I added some comments to explain the macro.
// loc1 is initialized earlier on
GetFileList>%loc1%\*.avi,files
Separate>files,;,file_names
Let>L=0
//start of loop
Repeat>L
Let>L=L+1
gosub>convert
MoveFile>file_names_%L%,loc3
wait>1
Until>L,file_names_count
// this sub-routine is for controlling a program, going through this takes about 1 minute. I also tried to embed this in the repeat-until loop, but that does not seem to make any difference.
SRT>convert
wait>1
SetFocus>avi to avi
wait>0.1
Press Tab
wait>0.1
Press Enter
wait>0.1
Send Character/Text>file_names_%L%
wait>0.1
Press Enter
wait>0.5
Press Tab
Press Enter
WaitwindowOpen>avi2avi
setfocus>avi2avi
wait>0.1
Press Enter
End>convert
I have this macro with two Repeat-Until loops. The strange thing about it is that one loop work fine, but the other not. For some reason it does not loop (it continues in the macro after executing the commands in the loop once). Does anyone have any idea why this second repeat-until loop does not work?
Here's (part of) the macro. I added some comments to explain the macro.
// loc1 is initialized earlier on
GetFileList>%loc1%\*.avi,files
Separate>files,;,file_names
Let>L=0
//start of loop
Repeat>L
Let>L=L+1
gosub>convert
MoveFile>file_names_%L%,loc3
wait>1
Until>L,file_names_count
// this sub-routine is for controlling a program, going through this takes about 1 minute. I also tried to embed this in the repeat-until loop, but that does not seem to make any difference.
SRT>convert
wait>1
SetFocus>avi to avi
wait>0.1
Press Tab
wait>0.1
Press Enter
wait>0.1
Send Character/Text>file_names_%L%
wait>0.1
Press Enter
wait>0.5
Press Tab
Press Enter
WaitwindowOpen>avi2avi
setfocus>avi2avi
wait>0.1
Press Enter
End>convert
Looking at what you've posted, I don't see any obvious problems.
I ran your code sample by defining your file location variables and renaming the windows opened from "avi2avi" and "avi to avi" to notepad. I had no trouble with it, repeat loops though all of the files. However, I was not performing whatever action the "avi2avi" or "avi to avi" program performs.
This is the second Repeat loop, tell us about the first loop. Explain why you think this one is not repeating. What version of Macro Scheduler are you using?
Good luck,
Dick
I ran your code sample by defining your file location variables and renaming the windows opened from "avi2avi" and "avi to avi" to notepad. I had no trouble with it, repeat loops though all of the files. However, I was not performing whatever action the "avi2avi" or "avi to avi" program performs.
This is the second Repeat loop, tell us about the first loop. Explain why you think this one is not repeating. What version of Macro Scheduler are you using?
Good luck,
Dick
I agree. I too believe the code is correct. And it works fine if you use notepad in stead of "avi2avi" and "avi to avi". For some reason the check at the end of the Repeat loop matches. So, the counter (letter L) matches the file_names_count. Looking at the watch list, reveals:
L=1
file_names_count=3
Regarding the second loop:
Actually, his is the first of the two loops. the second one moves files from one folder to another, untill there are no more files. Below you can find the second one. I changed the counter from the first loop to "L", to prevent any confusion, between the counters of the two loops.
GetFileList>%loc1%\*.avi,files
Separate>files,;,file_names
Let>k=0
Repeat>k
Let>k=k+1
MoveFile>file_names_%k%,loc2
wait>5
Until>k,file_names_count
Does this info help?
btw: I am using 7.4.008 Registered version
cheers,
Tobias
L=1
file_names_count=3
Regarding the second loop:
Actually, his is the first of the two loops. the second one moves files from one folder to another, untill there are no more files. Below you can find the second one. I changed the counter from the first loop to "L", to prevent any confusion, between the counters of the two loops.
GetFileList>%loc1%\*.avi,files
Separate>files,;,file_names
Let>k=0
Repeat>k
Let>k=k+1
MoveFile>file_names_%k%,loc2
wait>5
Until>k,file_names_count
Does this info help?
btw: I am using 7.4.008 Registered version
cheers,
Tobias
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Prior to version 8.0.2 Repeat/Until required a unique loop counter variable, otherwise Until would loop back to the first Repeat in the script with a matching loop counter. So if you're running 7.4 make sure your loop counters are unique to each Repeat/Until block.
And use the debugger:
http://www.mjtnet.com/blog/2006/05/17/use-the-debugger/
And use the debugger:
http://www.mjtnet.com/blog/2006/05/17/use-the-debugger/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
On my computer I have a video capture card from ATI. If the software for this card is running, some hotkeys set up in Macro Scheduler fail to invoke their assigned scripts even though the key presses do not appear to do any action within ATI's software. I only say this to point out that video cards, video drivers and video programs in my experience, have shown to have tremendous impact on the operating system and how it performs. In other words... video related programs can do some weird stuff. Since your script loops on your computer when you remove the reference to the avi conversion program, my guess is that the program is performing some action that interferes with Macro Scheduler or the operating system or memory or who knows what.
Unless someone comes up with a resolution for your problem, I would suggest you try rewriting your loop. Instead of having your loop perform an action have it write a second script that performs the action. Then after the script writing loop completes, execute the newly written script. This will negate the problem of jumping out of the loop since there will be no loop in the second script. When the second script is finished, have a line in the first script to delete it.
This has not been tested. Its only an example of what I'm talking about.
I hope that this is helpful,
Dick
Unless someone comes up with a resolution for your problem, I would suggest you try rewriting your loop. Instead of having your loop perform an action have it write a second script that performs the action. Then after the script writing loop completes, execute the newly written script. This will negate the problem of jumping out of the loop since there will be no loop in the second script. When the second script is finished, have a line in the first script to delete it.
This has not been tested. Its only an example of what I'm talking about.
I hope that this is helpful,
Dick
Code: Select all
//Establish a script file name
Let>scriptfile=%TEMP_DIR%~avi2avi_script~.scr
//In case the script exists, delete it
IfFileExists>%scriptfile%
DeleteFile>%scriptfile%
EndIF
// loc1 is initialized earlier on
GetFileList>%loc1%\*.avi,files
Separate>files,;,file_names
Let>L=0
//start of loop
Repeat>L
Let>L=L+1
//create variable for use in loop
Let>value=file_names_%L%
//Use the subroutine to create a line by line script.
gosub>convert
MoveFile>file_names_%L%,loc3
wait>1
Until>L,file_names_count
//Run the newly created script
Macro>%scriptfile%
//The script has run, delete it
IfFileExists>%scriptfile%
DeleteFile>%scriptfile%
EndIF
// this sub-routine is for controlling a program, going through this takes about 1 minute. I also tried to embed this in the repeat-until loop, but that does not seem to make any difference.
SRT>convert
writeLn>%scriptfile%,wresult,wait>1
writeLn>%scriptfile%,wresult,SetFocus>avi to avi
writeLn>%scriptfile%,wresult,wait>0.1
writeLn>%scriptfile%,wresult,Press Tab
writeLn>%scriptfile%,wresult,wait>0.1
writeLn>%scriptfile%,wresult,Press Enter
writeLn>%scriptfile%,wresult,wait>0.1
writeLn>%scriptfile%,wresult,Send Character/Text>%value%
writeLn>%scriptfile%,wresult,wait>0.1
writeLn>%scriptfile%,wresult,Press Enter
writeLn>%scriptfile%,wresult,wait>0.5
writeLn>%scriptfile%,wresult,Press Tab
writeLn>%scriptfile%,wresult,Press Enter
writeLn>%scriptfile%,wresult,WaitwindowOpen>avi2avi
writeLn>%scriptfile%,wresult,setfocus>avi2avi
writeLn>%scriptfile%,wresult,wait>0.1
writeLn>%scriptfile%,wresult,Press Enter
End>convert
-
- Junior Coder
- Posts: 35
- Joined: Thu Jan 12, 2006 9:20 pm
- Contact:
I'm having an issue with a repeat/until loop
I've got a repeat/until loop with a couple of embedded if statements. All of the statements execute but it hangs at the Until. I turned on logging and I can see that it starts and ends each line in the script except the until statement.
The script is for executing commands in a custom program and I'm trying to do exception handling within the loop with the if statements. I have the messagemodal's in there for de-bugging. When this script hangs I have to force it closed (Shift+esc won't work).
I'm not sure why this isn't working unless I'm missing something. I'm using MacroScheduler 8.04. See my script and the log data below...
Script Code:
Let>NumProds=2
Let>z=0
Repeat>z
Let>z=z+1
Press ALT
Send>d
Release ALT
MessageModal>Start of Step %z%
/*
May need to change wait parameter if system is slow
*/
IfWindowOpen>Data is Missing
Press ENTER
Press DEL
Send>3
Press ALT
Send>d
Release ALT
Press Down
MessageModal>It Worked Step %z%
Else
IfWindowOpen>POP
Press ENTER
Press Shift
Press TAB
Press TAB
Release Shift
Send>S
Press ALT
Send>d
Release ALT
Press Down
Else
Press Down
MessageModal>No errors step %z%
EndIf
EndIf
MessageModal>We made it out of the if statement, step %z%
Until>z=NumProds
Data from Log File showing last line started:
07/Sep/2006 14:42:56:187 - START: Let>NumProds=2
07/Sep/2006 14:42:56:203 - END: Let>NumProds=2
07/Sep/2006 14:42:56:203 - START: Let>z=0
07/Sep/2006 14:42:56:203 - END: Let>z=0
07/Sep/2006 14:42:56:218 - START: Repeat>z
07/Sep/2006 14:42:56:218 - END: Repeat>z
07/Sep/2006 14:42:56:234 - START: Let>z=z+1
07/Sep/2006 14:42:56:234 - END: Let>z=z+1
07/Sep/2006 14:42:56:234 - START: Press ALT
07/Sep/2006 14:42:56:250 - END: Press ALT
07/Sep/2006 14:42:56:250 - START: Send>d
07/Sep/2006 14:42:56:250 - END: Send>d
07/Sep/2006 14:42:56:265 - START: Release ALT
07/Sep/2006 14:42:56:265 - END: Release ALT
07/Sep/2006 14:42:56:265 - START: MessageModal>Start of Step 1
07/Sep/2006 14:43:01:312 - END: MessageModal>Start of Step 1
07/Sep/2006 14:43:01:328 - START: /*
07/Sep/2006 14:43:01:328 - END: /*
07/Sep/2006 14:43:01:328 - START:
07/Sep/2006 14:43:01:343 - END:
07/Sep/2006 14:43:01:343 - START: IfWindowOpen>Data is Missing
07/Sep/2006 14:43:01:343 - END: Else
07/Sep/2006 14:43:01:359 - START: IfWindowOpen>POP
07/Sep/2006 14:43:01:359 - END: Else
07/Sep/2006 14:43:01:359 - START: Press Down
07/Sep/2006 14:43:01:375 - END: Press Down
07/Sep/2006 14:43:01:375 - START: MessageModal>No errors step 1
07/Sep/2006 14:43:02:828 - END: MessageModal>No errors step 1
07/Sep/2006 14:43:02:843 - START: EndIf
07/Sep/2006 14:43:02:843 - END: EndIf
07/Sep/2006 14:43:02:843 - START: EndIf
07/Sep/2006 14:43:02:859 - END: EndIf
07/Sep/2006 14:43:02:859 - START: MessageModal>We made it out of the if statement, step 1
07/Sep/2006 14:43:04:250 - END: MessageModal>We made it out of the if statement, step 1
07/Sep/2006 14:43:04:265 - START: Until>z=NumProds
The script is for executing commands in a custom program and I'm trying to do exception handling within the loop with the if statements. I have the messagemodal's in there for de-bugging. When this script hangs I have to force it closed (Shift+esc won't work).
I'm not sure why this isn't working unless I'm missing something. I'm using MacroScheduler 8.04. See my script and the log data below...
Script Code:
Let>NumProds=2
Let>z=0
Repeat>z
Let>z=z+1
Press ALT
Send>d
Release ALT
MessageModal>Start of Step %z%
/*
May need to change wait parameter if system is slow
*/
IfWindowOpen>Data is Missing
Press ENTER
Press DEL
Send>3
Press ALT
Send>d
Release ALT
Press Down
MessageModal>It Worked Step %z%
Else
IfWindowOpen>POP
Press ENTER
Press Shift
Press TAB
Press TAB
Release Shift
Send>S
Press ALT
Send>d
Release ALT
Press Down
Else
Press Down
MessageModal>No errors step %z%
EndIf
EndIf
MessageModal>We made it out of the if statement, step %z%
Until>z=NumProds
Data from Log File showing last line started:
07/Sep/2006 14:42:56:187 - START: Let>NumProds=2
07/Sep/2006 14:42:56:203 - END: Let>NumProds=2
07/Sep/2006 14:42:56:203 - START: Let>z=0
07/Sep/2006 14:42:56:203 - END: Let>z=0
07/Sep/2006 14:42:56:218 - START: Repeat>z
07/Sep/2006 14:42:56:218 - END: Repeat>z
07/Sep/2006 14:42:56:234 - START: Let>z=z+1
07/Sep/2006 14:42:56:234 - END: Let>z=z+1
07/Sep/2006 14:42:56:234 - START: Press ALT
07/Sep/2006 14:42:56:250 - END: Press ALT
07/Sep/2006 14:42:56:250 - START: Send>d
07/Sep/2006 14:42:56:250 - END: Send>d
07/Sep/2006 14:42:56:265 - START: Release ALT
07/Sep/2006 14:42:56:265 - END: Release ALT
07/Sep/2006 14:42:56:265 - START: MessageModal>Start of Step 1
07/Sep/2006 14:43:01:312 - END: MessageModal>Start of Step 1
07/Sep/2006 14:43:01:328 - START: /*
07/Sep/2006 14:43:01:328 - END: /*
07/Sep/2006 14:43:01:328 - START:
07/Sep/2006 14:43:01:343 - END:
07/Sep/2006 14:43:01:343 - START: IfWindowOpen>Data is Missing
07/Sep/2006 14:43:01:343 - END: Else
07/Sep/2006 14:43:01:359 - START: IfWindowOpen>POP
07/Sep/2006 14:43:01:359 - END: Else
07/Sep/2006 14:43:01:359 - START: Press Down
07/Sep/2006 14:43:01:375 - END: Press Down
07/Sep/2006 14:43:01:375 - START: MessageModal>No errors step 1
07/Sep/2006 14:43:02:828 - END: MessageModal>No errors step 1
07/Sep/2006 14:43:02:843 - START: EndIf
07/Sep/2006 14:43:02:843 - END: EndIf
07/Sep/2006 14:43:02:843 - START: EndIf
07/Sep/2006 14:43:02:859 - END: EndIf
07/Sep/2006 14:43:02:859 - START: MessageModal>We made it out of the if statement, step 1
07/Sep/2006 14:43:04:250 - END: MessageModal>We made it out of the if statement, step 1
07/Sep/2006 14:43:04:265 - START: Until>z=NumProds
Doug Hazelman
Bennett Adelson
Infrastructure Group
Bennett Adelson
Infrastructure Group
Hi,
It seems I've got a working alternative. I've replace the Repeat with a Label tag and the Until with an If and a Goto statement. This seems to be working fine (I'm still testing though).
Thanks everybody (especially JRL)!
Marcus: I'm still interested in any kind of explanation you might have in this.
This is what I'm using now:
GetFileList>%loc1%\*.avi,files
Separate>files,;,file_names
Let>L=0
Label>loop
Let>L=L+1
gosub>convert
MoveFile>file_names_%L%,loc3
wait>1
if>file_names_count>L
goto>loop
endif
It seems I've got a working alternative. I've replace the Repeat with a Label tag and the Until with an If and a Goto statement. This seems to be working fine (I'm still testing though).
Thanks everybody (especially JRL)!
Marcus: I'm still interested in any kind of explanation you might have in this.
This is what I'm using now:
GetFileList>%loc1%\*.avi,files
Separate>files,;,file_names
Let>L=0
Label>loop
Let>L=L+1
gosub>convert
MoveFile>file_names_%L%,loc3
wait>1
if>file_names_count>L
goto>loop
endif
it was the comment lines
all,
thanks for the suggestions but nothing worked. while working with another repeat/until I noticed the same behavior after I inserted a comment line.
removing the comment lines from inside the repeat/until fixed the issue of it hanging.
thanks for the suggestions but nothing worked. while working with another repeat/until I noticed the same behavior after I inserted a comment line.
removing the comment lines from inside the repeat/until fixed the issue of it hanging.
Doug Hazelman
Bennett Adelson
Infrastructure Group
Bennett Adelson
Infrastructure Group
- Marcus Tettmar
- Site Admin
- Posts: 7395
- Joined: Thu Sep 19, 2002 3:00 pm
- Location: Dorset, UK
- Contact:
Ouch. I see there is indeed a problem with block comments inside Repeat/Until loops. I'll ensure that this is fixed. Thank you.
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar
Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?