Repeat-until loop does not work

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Tobias
Junior Coder
Posts: 22
Joined: Mon Jul 19, 2004 1:44 pm
Location: The Netherlands

Repeat-until loop does not work

Post by Tobias » Wed Sep 06, 2006 8:36 am

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

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Wed Sep 06, 2006 12:48 pm

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

Tobias
Junior Coder
Posts: 22
Joined: Mon Jul 19, 2004 1:44 pm
Location: The Netherlands

Post by Tobias » Thu Sep 07, 2006 1:42 pm

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

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Thu Sep 07, 2006 1:55 pm

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/
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Sep 07, 2006 2:59 pm

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

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

chihuahualand
Junior Coder
Posts: 35
Joined: Thu Jan 12, 2006 9:20 pm
Contact:

Post by chihuahualand » Thu Sep 07, 2006 7:00 pm

On version 7.4.009, I was getting awkward results with the repeat/until loops... I recoded using a counter/if>counter... I didn't save the old code... so I can't defend this post..., but, as it turned out, I like the "look" of the counter/if>counter coding better

dhazelman
Newbie
Posts: 3
Joined: Thu Sep 07, 2006 9:45 pm
Location: Ohio

I'm having an issue with a repeat/until loop

Post by dhazelman » Thu Sep 07, 2006 10:06 pm

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
Doug Hazelman
Bennett Adelson
Infrastructure Group

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Thu Sep 07, 2006 10:15 pm

Maybe:

Until>z=%NumProds%

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Thu Sep 07, 2006 10:28 pm

I tried this and it locked up on me also. I resolved it by adding a Wait>1 after the Until> line. Apparently Until> can't be the last line of a script.

Hope this helps,
Dick

dhazelman
Newbie
Posts: 3
Joined: Thu Sep 07, 2006 9:45 pm
Location: Ohio

Post by dhazelman » Thu Sep 07, 2006 10:30 pm

Thanks, I'll try this tomorrow!
Doug Hazelman
Bennett Adelson
Infrastructure Group

Tobias
Junior Coder
Posts: 22
Joined: Mon Jul 19, 2004 1:44 pm
Location: The Netherlands

Post by Tobias » Fri Sep 08, 2006 7:01 am

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

dhazelman
Newbie
Posts: 3
Joined: Thu Sep 07, 2006 9:45 pm
Location: Ohio

it was the comment lines

Post by dhazelman » Fri Sep 08, 2006 2:42 pm

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.
Doug Hazelman
Bennett Adelson
Infrastructure Group

Me_again
Automation Wizard
Posts: 1101
Joined: Fri Jan 07, 2005 5:55 pm
Location: Somewhere else on the planet

Post by Me_again » Fri Sep 08, 2006 2:50 pm

Good catch. I think you'll find it's OK to use

//comment

but not

/*
comment
*/

User avatar
Marcus Tettmar
Site Admin
Posts: 7395
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Fri Sep 08, 2006 2:51 pm

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?

User avatar
JRL
Automation Wizard
Posts: 3526
Joined: Mon Jan 10, 2005 6:22 pm
Location: Iowa

Post by JRL » Fri Sep 08, 2006 4:24 pm

:oops:
I should have noticed right away, I had this problem before. Sorry

Bugtracker #123

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