Repeat Until Occasionally Fails to Exit

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
evangelmike
Pro Scripter
Posts: 56
Joined: Sun May 11, 2008 9:39 pm

Repeat Until Occasionally Fails to Exit

Post by evangelmike » Sat Aug 09, 2008 9:14 pm

NOTE: I previously had listed the code as modified (incorrectly it turns out) in an attempt to solve the original 15% failure to exit the Repeat Loop properly problem. The original code with the Repeat Until loop which would not exit properly is listed below. The only difference between the two sets of code is in the next to last line which was originally Until>SRanges=MxNrRngs as shown below. It was this Repeat Loop as shown below which failed to exit properly about 15% of the time. When I attempted to fix the problem by changing the next to last line to Until>SRanges>MxNrRngs-1, the loop failed to exit properly 100% of the time (due to Until currently only being able to handle a single term variable). I have no explanation as to why having the next to last instruction as Until>SRanges=MxNrRngs would cause failure to exit the Repeat Loop about 15% of the time.

The following code is done just before exiting a large macro:

[code]
Let>SRanges=0
Repeat>SRanges
Let>SRanges=SRanges+1
If>SRanges>3,ExitRepeat
Let>SSStartMonth=StartMonth[%SRanges%]
Len>SSStartMonth,SLen
If>SLen=1
Let>SSStartMonth=0
ConCat>SSStartMonth,StartMonth[%SRanges%]
Endif
Let>SSStartDay=StartDay[%SRanges%]
Len>SSStartDay,SLen
If>SLen=1
Let>SSStartDay=0
ConCat>SSStartDay,StartDay[%SRanges%]
Endif
ConCat>SSStartMonth,_
ConCat>SSStartMonth,SSStartDay
Send>%SSStartMonth%%CR%
Wait>0.2
// Note: There was not TooMuchData; Therefore the logic between the
// following If and its EndIf was not executed
If>TooMuchData[%SRanges%]=TRUE
// If Too Much Data, set date to Bold and Red
Wait>0.2
Press Up
Wait>0.2
Press Shift
Wait>0.2
Press F10
Wait>0.2
Release Shift
Wait>0.2
Send>f
Wait>0.2
Press Alt
Wait>0.2
Send>o
Wait>0.2
Release Alt
Wait>0.2
Send>b
Wait>0.2
Press Down
Wait>0.2
Press Alt
Wait>0.2
Send>c
Wait>0.2
Release Alt
Wait>0.2
Press Tab * 7
Wait>0.2
Press Enter
Wait>0.2
Press Tab
Wait>0.2
Press Enter
Wait>0.2
Press Enter
Endif
Wait>0.2
Until>SRanges=MxNrRngs
Label>ExitRepeat
[/code]

This Repeat loop was occasionally failing to exit when SRanges was equal to MxNrRngs with both being equal to 3. My workaround is shown at line 4 where I exit if SRanges>3. (The workaround never fails to exit if the Repeat Loop has failed to exit when its condition was met.) SrRanges would never ordinarily be 3 at line 4 for the Repeat loop should have exited before SRanges was incremented again. Anyone have any ideas why this repeat loop might occasionally fail (about 15% of the time)?
Thanks in advance for your help. I should add that when I run this large macro on a slower computer with STEP_DELAY=0.125, the repeat loop never fails.
Last edited by evangelmike on Sun Aug 10, 2008 8:44 pm, edited 5 times in total.
May you have a blessed day!

Michael D Fitzpatrick
Reg. US Patent Agent

evangelmike
Pro Scripter
Posts: 56
Joined: Sun May 11, 2008 9:39 pm

Complex Expresssion in Repeat Until Yields Odd Result

Post by evangelmike » Sun Aug 10, 2008 12:25 am

Greetings! I wrote and executed the following macro with a very surprising result:

[code]
Let>MxNrRngs=3
Let>SRanges=0
Repeat>SRanges
Let>SRanges=SRanges+1
If>SRanges>3
MessageModal>SRanges = %SRanges%, MxNrRngs = %MxNrRngs%
Wait>0.4
Goto>ExitRepeat
Endif
Wait>0.2
Until>{%SRanges%>%MxNrRngs%-1}
MessageModal>HEREOK!!!
Label>ExitRepeat
MessageModal>SRanges = %SRanges%
[/code]

The Message HEREOK!!! displayed, followed by the Message:
SRanges = 1. In other words, this repeat loop just executed once. No diagnostic was displayed. Perhaps Until> cannot handle complex expressions. If not, a diagnostic should be displayed.

I then wrote and executed the following macro:

[code]
Let>MxNrRngs=3
Let>SRanges=0
Repeat>SRanges
Let>SRanges=SRanges+1
If>SRanges>3
MessageModal>SRanges = %SRanges%, MxNrRngs = %MxNrRngs%
Wait>0.4
Goto>ExitRepeat
Endif
Wait>0.2
Until>SRanges>MxNrRngs-1
MessageModal>HEREOK!!!
Label>ExitRepeat
MessageModal>SRanges = %SRanges%
[/code]

and obtained the following displays:

SRanges = 4, MxNrRngs = 3 (Message is from Line 6 above)
SRanges = 4 (This message is from the last line above)

Thus, the Repeat loop continued for another loop even after SRanges was 3. Please note that the Message HEREOK!!! was not displayed, as the Repeat loop refused to exit. Indeed it will loop forever! No diagnostic message was displayed.

Finally, I wrote and executed the following macro:

[code]
Let>MxNrRngs=3
Let>SRanges=0
Repeat>SRanges
Let>SRanges=SRanges+1
If>SRanges>3
MessageModal>SRanges = %SRanges%, MxNrRngs = %MxNrRngs%
Wait>0.4
Goto>ExitRepeat
Endif
Wait>0.2
Let>MxNrRngsMinus1=MxNrRngs-1
Until>SRanges>MxNrRngsMinus1
MessageModal>HEREOK!!!
Label>ExitRepeat
MessageModal>SRanges = %SRanges%
[/code]

and obtained the following displays:
HEREOK!!!
SRanges = 3
which is correct. Apparently, the Until can only handle the very simplest of expressions.
May you have a blessed day!

Michael D Fitzpatrick
Reg. US Patent Agent

User avatar
Bob Hansen
Automation Wizard
Posts: 2475
Joined: Tue Sep 24, 2002 3:47 am
Location: Salem, New Hampshire, US
Contact:

Post by Bob Hansen » Sun Aug 10, 2008 12:53 am

I believe that the following expression will only translate to 1 or 0:
Until>{%SRanges%>%MxNrRngs%-1}

SRanges will be greater than MxNrRngs-1, or it will not.
If it is greater, then the result will be 1, so you get Until>1
If it is not greater, the the result will be 0, so you get Until>0
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

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