Bug found in the upper bound of UNTIL>

Technical support and scripting issues

Moderators: JRL, Dorian (MJT support)

Post Reply
armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Bug found in the upper bound of UNTIL>

Post by armsys » Mon Feb 07, 2005 12:12 pm

Let>User[1]=ARMSTRONG
Let>User[2]=BOB
Let>User[3]=CYBERCITIZEN
Let>User[4]=MTETTMAR
Let>User[5]=TERMINATOR
Let>User_Name={Upper(%User_Name%)}
Let>k=0
Repeat>k
Add>k,1
If>User[%k%]=User_Name
Let>Found=k
Let>k=11
Endif
Until>k,5
Msg>%Found% user[%Found%]

In the above script, let's assume the User_Name is ARMSTRONG.
Inside the Repeat>k construct, in the first loop, Found will be assigned to 1. In order to exit the Repeat>k construct, I assign k with 11. In this case, it's an infinite looping.

The only way to exist the Repeat>k construct, you must assign k, the upper bound, with 5 precisely. It doesn't make any sense. Semantically, it should be 5 or greater. In the current version ( 7.3.08 ), it must be precisely 5 and 5 only. If k is greater than 5, the above Repeat>k construct will run forever.

BTW, the second questin, I don't know how to display the element in user[%Found%], that's supposed to be "ARMSTRONG".

Your help will be greatly appreciated. Many thanks in advance.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Feb 07, 2005 12:22 pm

The definition is repeat until k EQUALS 5, so clearly setting k to 11 will cause an infinite loop. To me this makes perfect sense. In your example there is no need to jump out of the loop at all. The only time you might want to jump out of the loop would be if you had a large list and then I would simply use a Goto and a Label just after the Until statement. No need to set the loop counter to anything, but if you must, set it to the loop max.

To display the value in the array:
Let>user=user[%Found%]
Msg>%Found% %user%

This is my version of your example script:


Let>User[1]=ARMSTRONG
Let>User[2]=BOB
Let>User[3]=CYBERCITIZEN
Let>User[4]=MTETTMAR
Let>User[5]=TERMINATOR
Let>User_Name=CYBERCITIZEN
Let>User_Name={Upper(%User_Name%)}
Let>k=0
Let>Found=0
Repeat>k
Add>k,1
If>User[%k%]=User_Name
Let>Found=k
Goto>endloop
Endif
Until>k,5
Label>endloop
If>Found=0
Message>Not found
else
Let>user=user[%Found%]
Msg>%Found% %user%
endif


This version jumps out of the loop when found (though with this small list this is not necessary) and then displays "Not Found" if the name was not found. If it was found it displays your message.
MJT Net Support
[email protected]

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon Feb 07, 2005 12:56 pm

Hi Support,

Being a long time PL/1 and Clipper programmer previously, often GOTO and LABELs elude my mind completely when writing Macro Scheduler scripts. You're absolutely right. An elegant GOTO statement should have escaped the REPEAT construct. In particular, I'm grateful for your generous effort in re-writing the script.

As it turns out, to order to display the value of an eleement of the array, an extra step is required, that is, assigning the value to a variable. That's interesting!

BTW, lately I notice all your sample scripts are beatifully formatted. How do you do that? Are you using any program beautifier such as PolyStyle?

Thanks again for generous assistance.

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Feb 07, 2005 1:43 pm

If I remember Clipper had an Exit or Break command which would exit a loop.

Not sure what you mean about formatting my scripts - I'm just using the Macro Scheduler editor, as always.
MJT Net Support
[email protected]

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Mon Feb 07, 2005 2:12 pm

Hi Support,

That's exactly what I'm dreaming for but I know both Exit and Break won't be introduced into Macro Scheduler anytime sooner.

Since you mentioned about Clipper, I hope in future Macro Scheduler would support Do Case...End Case construct.

For the program beautifier, I mean an automatic text formatter like Evolve in Multi-Edit (Brief/dBrief during 80's). That's, all those commands within If...Else...Endif are properly indented. Do you do it manually?

User avatar
support
Automation Wizard
Posts: 1450
Joined: Sat Oct 19, 2002 4:38 pm
Location: London
Contact:

Post by support » Mon Feb 07, 2005 2:22 pm

Yes, I always format my code manually like this. I do it without thinking. However, you can block indent code in Macro Scheduler by highlighting the code to indent and selecting Edit/Block Indent.
MJT Net Support
[email protected]

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 » Mon Feb 07, 2005 3:45 pm

RE indenting, on the forum you may have to use

Code: Select all

[code]
     ...... 
     .....
     .....
[/code]
to preserve the indentation.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!

armsys
Automation Wizard
Posts: 1108
Joined: Wed Dec 04, 2002 10:28 am
Location: Hong Kong

Post by armsys » Tue Feb 08, 2005 11:13 am

Hi Bob,

Thank you for your tips. That may explain why all indentations of sample scripts were lost in my numerous posts.

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