Click to See Complete Forum and Search --> : Multi-dimensional or nested arrays in CR XI


cmatiuk
November 16th, 2007, 10:51 PM
Crystal Reports XI: I have the following input derived from an Access 2007 database query. The Report creates a form letter and groups on the uni_full field. The dynamic array that I’ve constructed, however, does not provide the output in a consolidated format as I would like. See the input, output examples, and code samples below. I’d really appreciate some assistance with this “multi-dimensional” or “nested array” problem—I’m really not sure how to call it. Thanks in advance for your suggestions.

Input:
-----
uni_full.............uni_univ..author_full.......comm_committee
Ronald Adams....OSU...,....R. Haggerty..,...Author
Ronald Adams....OSU.......Jeff McDonnell...Author
Ronald Adams....OSU.......Jeff McDonnell..Hydrologic Measurement Facility
Ronald Adams....OSU.......John Selker......Author
Ronald Adams....OSU.......John Selker.....Board of Directors (2005-2007)
Ronald Adams....OSU.......John Selker.....Hydrologic Measurement Facility

Current Output (I can build an array that will produce the following):
--------------------------------------------------------------------

Dear Ronald Adams (OSU),

The following people blah blah blah:

R. Haggerty (Author), Jeff McDonnell (Author), Jeff McDonnell (Hydrologic Measurement Facility), John Selker (Author), John Selker (Board of Directors (2005-2007)), John Selker (Hydrologic Measurement Facility).

Desired Output:
--------------

Dear Ronald Adams (OSU),

The following people blah blah blah:

R. Haggerty (Author), Jeff McDonnell (Author, Hydrologic Measurement Facility), John Selker (Author, Board of Directors (2005-2007), Hydrologic Measurement Facility).


I'm using this code to build the array:
-------------------------------------

//{@DynamicArrayBuilder}
whileprintingrecords;
stringvar array MyArrayComm;
global numbervar CountComm;

if not({qry_mailmerge_both.author_full} in MyArrayComm) then

(CountComm := CountComm + 1;

then (Redim Preserve MyArrayComm[CountComm];

MyArrayComm[CountComm] := {qry_mailmerge_both.author_full}+' ('+{qry_mailmerge_both.comm_committee}+')'));

And the following code to insert the array into the text:
--------------------------------------------------------

// used for displaying array info only
whileprintingrecords;
stringvar array MyArrayComm;
numbervar CountComm;
local stringvar PrintComms;
local stringvar LabelComms;
local numbervar i;

for i := 1 to CountComm step 1
do
(
if i = 1 then
(
PrintComms := MyArrayComm[i];
LabelComms := 'CUAHSI Author and/or Leadership Role: ';
)
else
(
PrintComms := PrintComms+', '+MyArrayComm[i];
LabelComms := 'CUAHSI Author and/or Leadership Roles: ';
)
);
LabelComms+PrintComms

cmatiuk
November 18th, 2007, 05:13 PM
The solution is a combination of the construction of the array and in examining the contents of the array "whileprintingrecords." The array's elements now contain a comma separating the name and the committee portions:

MyArrayComm[CountComm] := {qry_mailmerge_both.author_full}+','+{qry_mailmerge_both.comm_committee}));

The display code parses out the contents of the array element using the Split function and compares the "name" portion. If the name is the same in element "[i]" and "[i-1]" in the do loop, then do something else do something different in formating the output. The solution may be kludgy but it works.

// used for displaying array info
whileprintingrecords;
stringvar array MyArrayComm;
stringvar array ArrayCommIn; // new "temp" array
stringvar array ArrayCommPrint; // new "temp" array
numbervar CountComm;
local stringvar PrintComms;
local stringvar LabelComms;
local numbervar i;

for i := 1 to CountComm step 1
do
(
if i = 1 then
(
LabelComms := 'CUAHSI Author and/or Leadership Role: ';
ArrayCommIn := Split(MyArrayComm[i],',');
PrintComms := ArrayCommIn[1]+': ('+ArrayCommIn[2];
)
else
(
LabelComms := 'CUAHSI Author and/or Leadership Roles: ';
ArrayCommPrint := Split(MyArrayComm[i-1],',');
ArrayCommIn := Split(MyArrayComm[i],',');
if ArrayCommPrint[1] = ArrayCommIn[1] then
(
PrintComms := PrintComms+', '+ArrayCommIn[2];
)
else
(
PrintComms := PrintComms+'); '+ArrayCommIn[1]+': ('+ArrayCommIn[2];
)
)
);
LabelComms+PrintComms+')'