Technical Questions
 Crystal Reports Forum : Crystal Reports 9 through 2022 : Technical Questions
Message Icon Topic: Use Array to Print from multiple records Post Reply Post New Topic
Author Message
techiesue
Newbie
Newbie
Avatar

Joined: 06 Dec 2011
Location: United States
Online Status: Offline
Posts: 3
Quote techiesue Replybullet Topic: Use Array to Print from multiple records
    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
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet 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.
 
 
IP IP Logged
techiesue
Newbie
Newbie
Avatar

Joined: 06 Dec 2011
Location: United States
Online Status: Offline
Posts: 3
Quote techiesue Replybullet 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.
IP IP Logged
lockwelle
Moderator
Moderator


Joined: 21 Dec 2007
Online Status: Offline
Posts: 4372
Quote lockwelle Replybullet 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.


Edited by lockwelle - 07 Dec 2011 at 10:25am
IP IP Logged
techiesue
Newbie
Newbie
Avatar

Joined: 06 Dec 2011
Location: United States
Online Status: Offline
Posts: 3
Quote techiesue Replybullet 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.
IP IP Logged
Post Reply Post New Topic
Printable version Printable version

Forum Jump
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot delete your posts in this forum
You cannot edit your posts in this forum
You cannot create polls in this forum
You cannot vote in polls in this forum



This page was generated in 0.016 seconds.