Print Page | Close Window

Use Array to Print from multiple records

Printed From: Crystal Reports Book
Category: Crystal Reports 9 through 2020
Forum Name: Technical Questions
Forum Discription: Formulas, charting data, Crystal syntax, etc.
URL: http://www.crystalreportsbook.com/forum/forum_posts.asp?TID=15097
Printed Date: 18 May 2024 at 12:33am


Topic: Use Array to Print from multiple records
Posted By: techiesue
Subject: Use Array to Print from multiple records
Date Posted: 06 Dec 2011 at 12:25pm

How can I use an array to collect the values in a table column from multiple records that are associated with one header record to print on a single line?

For example, I have a USER table and an APPS table.  User_No is a unique key to the USER table, but there is a record in the APPS table for every application loaded on the user's PC (along with other info about the app).
 
I want to collect all the apps in an array and print them on one line (instead of one line per APPS record) when there is a break in User_No.
 
I'm stumped and can't figure out how to do this.
 
Any help offered would be appreciated.
 
Suzanne



Replies:
Posted By: lockwelle
Date Posted: 07 Dec 2011 at 4:36am
in the group header reset your array:
shared stringvar array x;
shared numbervar lastInd :=0;
 
redim x[100];
//allows up to 100 applications
 
in the group footer to display the applications:
shared stringvar array x;
shared numbervar lastInd;
local stringvar appList := "";
local numbervar ind;
for ind=1 to lastInd step 1 do(
  if x[ind] <> "" then
    appList := appList + ", " + x[ind];
);
 
mid(appList, 3);  //skip the first comma and space
 
in the detail section
shared numbervar lastInd;
shared stringvar array x;
lastInd := lastInd + 1;
x[lastInd] := {table.field};
 
 
should work, or at least is a good start.
 
 


Posted By: techiesue
Date Posted: 07 Dec 2011 at 9:41am
Thank you!  I think I am on the right track now although I'm only getting the last entry in the array to display in the footer.  I'm wondering , does the group header code to reset the array execute before each detail is processed? Anyway, I'm playing with it and am much further along than I would be without your help. Thank you again.


Posted By: lockwelle
Date Posted: 07 Dec 2011 at 10:24am
no, the group header code only executes once per group.
 
depending on how long the values are, you might try setting 'can grow' on...as CR will truncate.
 
you might also try adding something like:
if not isnull(x[ind]) and x[ind]<> "" then
 
CR is funny with null values.
 
HTH
 
you might also try printing/displaying what the last index is and what the prior values are...maybe a formula like:
shared stringvar x;
x[1]
 
something so you can try and 'see' what values CR has stored and if they are correct ones.


Posted By: techiesue
Date Posted: 07 Dec 2011 at 12:03pm

Oh what a difference a colon can make! Embarrassed  I was incrementing my lastind with lastind = lastind + 1 instead of lastind := lastind + 1...  Those simple things tend to take the longest to find.

Thanks again for your assistance.



Print Page | Close Window