Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with arrays & For loop

Status
Not open for further replies.

MTarkington

Programmer
Feb 14, 2001
73
US
Good afternoon,

I currently have a formula with the following code:

stringvar code1 := {history.code_authorized_1};

numbervar counter;
numbervar subscript;

stringvar array cpt_code := [filled with 70 data elements];

stringvar array code_value := [filled with 70 data elements];

for counter := 1 to 70 do
(
if code1 = cpt_code[counter] then
(
subscript := counter;
)
);
code_value[subscript];

END OF CODE

Now, I have 2 arrays that have corresponding data (cpt_code[1] directly corresponds to code_value[1] and so on). I want to be able to compare the variable code1 to the cpt_code array and display the code_value data that corresponds.

The above code only works for certain records. I have over 100 pages on this report, each DL is 1 record, and it only seems to be pulling the 10th item in the array, which is correct for the ones that it is displaying, however, it is not displaying any corresponding fields for the other records.

Any ideas or suggestions will be appreciated.

Thanks,
Mark
 
Mark,

Firstly by looking at your formula - your loop will go around 70 times for each record - regardles whether it finds the match it is looking for or not. Beside making thousands of unnecessary comparisons (after it has found the correct value and stored it) - try adding an Exit for after the "subscript := counter" line.

Your main problem is that you are not declaring the scope of the variable. (For example Local, Global, Shared) By omitting the the scope keyword - you are effectively making all of your variables Global - which means they retain the values assigned to them from formula to formula - which you dont want. Make each variable local!!!
Example: Local numbervar counter;

Cheers
paulmarr
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top