View previous topic :: View next topic
|
Author |
Message |
hariibm
New User
Joined: 05 Feb 2007 Posts: 61 Location: Chennai
|
|
|
|
Hi,
My REXX program will create count of various search results and puts the counts say CNT1,CNT2, CNT3 etc.
Now, I want to display these counts using SAY and I don't know how many counts would be there.
For displaying these counts, I want to use a loop instead of SAY for each count variable.
Please let me know how to achieve this.
I am using the below loop and not working.
DO J = 1 TO 10
SAY 'COUNT ' J CNT!!J
END |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
Use a STEM variable |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
why not use a stem and have stem.0 contain the number of entries?
as an alternative use the interpret instruction , but it needs more mastering skills
here is a sample of both approaches
Code: |
trace "O"
parse arg k
if k > 8 then ,
exit
say "filling the vars "
do i = 1 to k
say "name"i "= "i
interpret "name"i "= "i
end
say "showing what is there and what is not"
say "name1" name1
say "name2" name2
say "name3" name3
say "name4" name4
say "name5" name5
say "name6" name6
say "name7" name7
say "name8" name8
say "showing the vars "
do i = 1 to k
say "temp = name"i
interpret "temp = name"i
say "name"i temp
end
stem.0 = k
do i = 1 to k
stem.i = i
end
k = stem.0
do i = 1 to k
say "stem."i stem.i
end
exit
|
but working with INTERPRET might become quite painful, it' s not easy to decide at a glance what should be inside and outside quotes/apost's
a good way to debug INTERPRET issues is to precede it with a SAY instruction with the same right part ,
in this way You will see exactly what is going to be interpreted |
|
Back to top |
|
|
hariibm
New User
Joined: 05 Feb 2007 Posts: 61 Location: Chennai
|
|
|
|
Thanks expat and enrico.
Thanks especially for the introducing the INTERPRET option for me. |
|
Back to top |
|
|
acevedo
Active User
Joined: 11 May 2005 Posts: 344 Location: Spain
|
|
|
|
another option...
if CNT1,CNT2, CNT3 are already populated...
Code: |
cnt1=100
cnt2=200
cnt3=300 |
you can use the builtin VALUE instead of interpret
Code: |
do i = 1 to 3
temp=value("cnt"i)
say temp
end i |
|
|
Back to top |
|
|
acevedo
Active User
Joined: 11 May 2005 Posts: 344 Location: Spain
|
|
|
|
btw, in the example above I woud go for a stem, was just trying to show an option to INTERPRET. |
|
Back to top |
|
|
|