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

Collecting unique values for a group 1

Status
Not open for further replies.

BobLucas

MIS
Feb 13, 2009
7
US
My data consists of product, manufacturer, and function the manufacturer is authorized to perform (e.g., packaging, quality control, etc.). The data covers many different sites, and the manufacturer may be authorized for some functions at one site, and other functions at another site.
The user wants the report to ignore site and to show a list of unique function names that each manufacturer is authorized for. I've grouped the report by product and manufacturer, and am trying to accumulate unique function names into a string variable array. My problem is re-initializing the array on manufacturer group breaks.
Any suggestions?
 
Trying to get formulas to evaluate at particular times is new to me. What I have done is shown below, but it is producing no values, although I can confirm independently that the values exist. The version I am using is Crystal XI. Each operation on the array is defined within a formula placed in the relevant section.

Initialization (group header):
StringVar array funcNames;
redim funcNames [1];
""

Update (detail section):
StringVar array funcNames;
If not ({MASTER.FUNC_NAME} IN funcNames )Then
(Redim preserve funcNames [Count(funcNames)+1];
funcNames [Count(funcNames)] := {MASTER.FUNC_NAME};);
""

Print (group footer):
StringVar Array funcNames;
local StringVar x := Join(funcNames,ChrW(10));
x

An additional problem is the Detail section, which I do not want to show. As I understand it, suppressing it will cause the formula not to be evaluated. As it is, it takes up a small but significant amount of space on the report.

Any help would be appreciated
 
Try adapting something I wrote to collect postcodes:
Code:
// Accumulate using a formula field (suppressed) in the detail line.  Allow for nulls and blanks.
whileprintingrecords;
if not isnull({Recc.Postcode}) and {Recc.Postcode} <> " "
then stringvar pst := pst + {Recc.Postcode} +", "
else if length(pst) = 0 
then stringvar pst := pst + "Excluding blanks; "
else stringvar pst := pst
Code:
// Show in using a formula field in the group footer.
whileprintingrecords;
stringvar pst;
left(pst,len(pst)-2)
Code:
//  Clear using a formula field in the group header.
whileprintingrecords;
stringvar pst := "";
Note that clearing in the footer avoids problems with group headers repeating on a new page, which does clear everything for the group. Provided the 'clear' is placed in the section AFTER the display, it will do them in that order.


[yinyang] Madawc Williams (East Anglia, UK). Using Crystal 10 & 11.5 with Windows XP [yinyang]
 
Thank you!

I'm trying a subreport now, but if that doesn't work, I'll return to the formulat method.

This looks really useful anyway.
 
Change your formulas to:

//Initialization (group header):
whileprintingrecords;
StringVar array funcNames := "";
numbervar i := 0;

//Update (detail):
whileprintingrecords;
StringVar array funcNames;
If not ({MASTER.FUNC_NAME} IN funcNames) Then
(
Redim preserve funcNames [Count(funcNames)+1];
i := i + 1;
if i < Count(funcNames)+1) then
funcNames := {MASTER.FUNC_NAME}
);
""

//{@print} (group footer):
whileprintingrecords;
StringVar Array funcNames;
local StringVar x := Join(funcNames,ChrW(10));
x

Format the last formula to "can grow" so you can see the results. You also CAN suppress the detail section with no effect on the results.

You could use Madawc's suggestion, but you would have to add in a clause:

whileprintingrecords;
stringvar pst;
if not isnull({Recc.Postcode}) and
{Recc.Postcode} <> " " and
not({Recc.Postcode} in pst) then
pst := pst + {Recc.Postcode} +", " //..etc,

-LB
 
Thanks, LB. I tried your suggestion, but I'm getting a "Subscript must be between 1 and the size of the array" error on the assignment statement in the detail section. Code is below.

//Initialize array during group header evaluation
whileprintingrecords;
StringVar array funcNames := "";
NumberVar i := 0;

//Detail section - add element
whileprintingrecords;
StringVar array funcNames;
NumberVar i;
If not ({Master.FUNC_NAME} IN funcNames )Then
(
Redim preserve funcNames [Count(funcNames)+1];
If i<Count(funcNames)+1 Then
funcNames := {Master.FUNC_NAME} //ERROR HERE
);
i
 
Oops! I found the error already. It's working, and bless you!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top