Strings and variables together in the FOR loop?
Posted: Fri Jul 23, 2010 6:47 am
I wrote a long program performing a number of tests. Previously, I had just a couple of workfiles, so I specified strings/variables at the beginning of the program and changed them each time I ran the program:
Now I have dozens of workfiles, and I don't want to retype their names and specific values each time, since I often re-run the program. I also can't have a program for each workfile because I often update the program, and so I have to have only one program. So, my idea was to create the following loop:
Logically, each time the loop is run, each string and variable should be updated. For instance, in the first run, %name should take the value of %name_{!loop}, which is %name_1, which is wf1. But that simply doesn't work. The following error occurs:
Code: Select all
%name = "wf1" <-- here
!number = 100 <-- here
etc.
wfopen {%name}
[body of the program]
save {%name}
close {%name}
Code: Select all
%name_1 = "wf1"
%name_2 = "wf2"
%name_3 = "wf3"
!number_1 = 100
!number_2 = 50
!number_3 = 60
etc.
for !loop=1 to 3
%name = %name_{!loop}
%number = %number_{!loop}
etc.
wfopen {%name}
[body of the program]
save {%name}
close {%name}
next
Why does it not work? I also tried, for example, %name = %name_ + {!loop}, %name = {%name_} + {!loop}, %name = "%name_" + "{!loop}", etc., but none of these worked. The very first one (%name = %name_ + {!loop}) makes sense, and it should work. I also tried to start the loop at the very beginning of the program, but that shouldn't make any difference, and it didn't--it didn't work. What do you think the reason is?No workfile exists - Use NEW or OPEN to create or load a workfile in "%NAME" = "wf1"