Print Page | Close Window

Array?

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=12877
Printed Date: 06 May 2024 at 1:04pm


Topic: Array?
Posted By: jbalbo
Subject: Array?
Date Posted: 11 Apr 2011 at 6:19am
Hi,
 
Is there a way to create an array on a report footer?
I have a detail section which displays a rank and a code
I want to keep track of codes which have a rank of 1
so in the footer if a client has more than 1 rank of 1 then it displays 1, 2, or 3 etc
 
example
 
client1 has 1 rank of 1 with code 200
 
footer displays
client1  200
 
client2 has 1 rank of 1 with code 200 and 1 with 250
footer displays
client2  200, 250
 
 
 
Thanks
Joe
 



Replies:
Posted By: Keikoku
Date Posted: 11 Apr 2011 at 6:34am
You can create a string representation of an array using several formulas.

You will need:

-one formula in the report header to initialize an empty string.
-one formula in the group header that will append the group name to it (assuming you group on "client1" etc)
-one formula in the detail section that will append the code to the string
-one formula in the group footer section to insert new-line characters (use the chr() function for this)
-one formula in the report footer that will print the string.

All formulas should use the "whileprintingrecords" keyword. They will all use the same global variable.

An example initialization formula would be


whileprintingrecords;
global stringvar output := "";


and a group header formula would be


whileprintingrecords;
global stringvar output := output & " " & {group_name}


In the end you should get something like


Client1   200
Client2   300,400,
Client3   250,450,


Dealing with the comma at the end may be difficult.


Posted By: jbalbo
Date Posted: 11 Apr 2011 at 8:59am
Ok,
 
So I got this kind of working
 
 GH: @reset -
whileprintingrecords;stringvar x := "";
 
Display @accum -
 if {Axis1Link.RANK}=1 then
whileprintingrecords;stringvar x := x + {Axis1.Code} + ", ";
 
GF: @display -
 whileprintingrecords;stringvar x;stringvar array y := split(x,", ");numbervar j := ubound(y)-1;left(x,instr(x,y[j])-1)+ (if j > 1 then "and "+ y[j]else y[j])
 
But my detail doesn't seem to want to do my If statement .
 
I only want them added if {Axis1Link.RANK}=1
 
Thanks

 


Posted By: Keikoku
Date Posted: 11 Apr 2011 at 9:43am
whileprintingrecords; //set evaluation time
stringvar x; //declare variable
if {Axis1Link.RANK}=1 then
   x := x & {Axis1.Code} & ", ";

Unless you are using basic (which I've never used), & is the crystal syntax for concatenation.


Posted By: jbalbo
Date Posted: 11 Apr 2011 at 10:03am
Thanks for getting back any chance you can explain further?
 
I found the code I used online, your way looks simpler..
Thanks
Joe
 


Posted By: Keikoku
Date Posted: 11 Apr 2011 at 10:19am
Not sure what more there is to explain.
Which part are you having trouble with?

Your display formula seems quite complicated.

It doesn't seem like an array is necessary in this case if you only want to show information.

Array is only necessary if you need to store multiple records and retrieve them at the end.

You should able to construct your string "as you go" and just print it out at the end.


Posted By: jbalbo
Date Posted: 11 Apr 2011 at 10:26am
thanks for getting back , sorry I cant get this!!
Ok so this is what I have
in my detail  I show axis1link.rank and axis1.code
But I will be surpressing that
and in the footer I only want to display
axis1.codes that axislink.rank = 1 , but display in array fashion like
502.1, 503.1
 
Thanks
 Joe
 
 
in the group footer I wan


Posted By: Keikoku
Date Posted: 11 Apr 2011 at 5:12pm
You should construct your string in that fashion then.

x := x & " " & {code} & "." & {rank} & ", "

Then if code = 501 and rank = 1, you will have something like

501.1, 502.1, ..., 509.1,

If the last comma is aesthetically unpleasing, then in your print formula you should write

x[1 to length(x) - 2)]

This basically says to print everything except the last two characters, which from above we can see is the comma followed by a space.


Posted By: jbalbo
Date Posted: 12 Apr 2011 at 2:57am
Thanks Keikoku,
 
This works great in the details :
whileprintingrecords; //set evaluation time
stringvar x; //declare variable
if {Axis1Link.RANK}=1 then
   x := x & {Axis1.Code} & ", ";
 
But can I display the final tally in the GF?
it seems to rest if I put it in the footer..
 
Thanks
 


Posted By: Keikoku
Date Posted: 12 Apr 2011 at 3:11am
it seems to reset if I put it in the footer..


Do you want to display it in the *report footer* or the group footer?

I think the display should be fine in the group footer.

Ok,

So I got this kind of working

GH: @reset -
whileprintingrecords;stringvar x := "";


This is why it's resetting.


Posted By: jbalbo
Date Posted: 12 Apr 2011 at 3:30am
group footer, is reseting.??
I have the initial reset in the group header
 
I want to display the accumulated result in the group footer.
Let me check if maybe I have some surpress on?
 


Posted By: jbalbo
Date Posted: 12 Apr 2011 at 3:34am
I did have a surpress on sorry..
 
Now in the GF it display the last value a second time, can I avoid that?
 
Thanks..


Posted By: Keikoku
Date Posted: 12 Apr 2011 at 3:46am
Now in the GF it display the last value a second time, can I avoid that?


"Last value" refers to the last record in the group?
ie: given a group with the codes

I'm guessing since you used suppression, you now have duplicate records in your group which you do not want to record.

I guess in this scenario, you could initialize an array in the GH and then add values to it from the details. You would check whether the current code exists in the array or not, and then add it if it doesn't.

This will ensure that you have an array with unique values. You can then construct a string from the array in your display formula.



Print Page | Close Window