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.
Bug found in the upper bound of UNTIL>
Moderators: JRL, Dorian (MJT support)
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.
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]
[email protected]
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.
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.
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.
Not sure what you mean about formatting my scripts - I'm just using the Macro Scheduler editor, as always.
MJT Net Support
[email protected]
[email protected]
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?
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?
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]
[email protected]
- Bob Hansen
- Automation Wizard
- Posts: 2475
- Joined: Tue Sep 24, 2002 3:47 am
- Location: Salem, New Hampshire, US
- Contact:
RE indenting, on the forum you may have to use
[/code]
to preserve the indentation.
Code: Select all
[code]
......
.....
.....
to preserve the indentation.
Hope this was helpful..................good luck,
Bob
A humble man and PROUD of it!
Bob
A humble man and PROUD of it!