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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

While Do Loop error -- evaluated more than max number

Status
Not open for further replies.

pcassada

Technical User
Nov 3, 2000
7
US
Hello Crystal Masters!

(I am using Crystal 8.5)

I am in the process of using a while do loop to break down a list of comma separated codes, compare each code to a table that holds a description for that code and then put the descriptions into a commas separated list. The codes are various lengths but there are no spaces between and they are separated by commas. All the codes have corresponding descriptions.
Here is an example of databaseField: A23,Q1234,D241,V2
Here is an example of the table
A23 Apple 23
B2 Bee 2
C234 Cat 2
Q1234 Queen 1234
etc


This is what I have done so far:

Shared StringVar databaseField;
Shared NumberVar stringLen:= length(databaseField);
Shared StringVar list:= ' ';
Shared StringVar code:= {Gen_Tables.CODE};
Shared StringVar desc:= {Gen_Tables.DESCRIPTION};
Shared StringVar outString;

Local NumberVar a := 1;
Local NumberVar b := 1;
While a <= stringLen and
InStr(databaseField,&quot;,&quot;) > 0
Do
(

a:= Instr(a,noCommas2,&quot;,&quot;) -1;
Local stringVar c2:= databaseField[b to a];

If c2 = code then list2 := desc + ' a ' + totext(a) +
' b ' + totext(b);

a:= a + 1;
b:= a;


);

//these gather the commas separated descriptions into two

if length(list) > 3
then
outString:= outString + ', ' + list;

If I take out the While Do part then I can get the first code in the field to work but if I leave the While Do loop in then I get the &quot;A loop was evaluated more than the maximum number of times allowed&quot; error message.
I have been able to do this with single letter codes but not multiple.
Any help would be appreciated.

PCassada
 
my guess is that you have no provision for what happens when there is &quot;No Match&quot; for the code in the string and you end up in an endless loop that times-out.

I say guess...since you have not given the complete formula since some variables are not defined...such as &quot;list2, c2 and noCommas2&quot;

from the looks of things if this formula is being placed in the detail line....then you are getting a code and description from your database and trying to see if code is found in this comma-delimited string (databasefield).

you don't need a while - do function to do this.

the Instr function by itself will work just fine.

something like:

Shared StringVar databaseField;
Shared StringVar list := &quot;&quot;;
Shared StringVar code := {Gen_Tables.CODE};
Shared StringVar desc := {Gen_Tables.DESCRIPTION};

//wrap the code in quotes
stringVar test := &quot;,&quot; + code + &quot;,&quot;;

//Placing the descriptions into a comma delimited list if found
if instr(databaseField,test) <> 0 then
list := List + desc + &quot;,&quot;

this is much easier to work with and faster too. I assume that this is a subreport because of all the Shared variables

Anyway Hope this guides you...If I have missed anything in this interpretation then post and we shall take another crack at it.

Happy New Year
Jim
 
You might want to consider splitting the string into an Array and handling each element seperately that way.

stringvar mylist:=split(databasefield,&quot;,&quot;)

then Count(mylist) is how many elements you've got in the list, and it might be a whole easier to handle.

And you can join ti all abck together again with

Join(newlist,&quot;,&quot;) Editor and Publisher of Crystal Clear
 
Thank you both for your comments! Sorry it has taken me so long to let you know the results of your labor; we have had some bad weather here.

After a little tweaking, Ngolem's suggestion works quite nicely. I tried using chelseatech's suggestion as well but could not use split.

Here is what I ended up with:

From the main report I sent the info from the database in the Shared StringVar dbfield (there is a validation table on the field in the database so only codes in the table can be used)to the subreport.

This is the code in the subreport; it uses the dbfield variable, compares it to the codes in the table and produces a comma separated description list of the codes

Shared StringVar dbfield;
Shared StringVar list;
Shared StringVar code := {Gen_Tables.CODE};
Shared StringVar desc := {Gen_Tables.DESCRIPTION};

if instr(dbfield,code) <> 0 then
list := list +&quot;, &quot;+ desc

then the list is sent back to the main report where the comma at the beginning of the string is removed and the new comma separated description list is displayed!


I should have tried the forum along time ago.

Thanks again,
Pcassada

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top