mbroad02
asked on
Crystal Reports-Use an array variable to store dynamic data
Hello--I have an existing complex report which I need to modify in the following way. The report uses a sub-report to locate names (First, middle and Last) associated with a case. Since the names and number of associated names are not known in advance, I would like to explore the usage of an array variable.
What I am envisioning is something like this:
Inital set-up in sub-report
Declare array variable
Declare subscript
Read loop
READ 1st NAME in sub-report
Set subscript up by 1
move name to array variable (subscript)
After sub-report has finished for that case, I envision the formula in the main report doing something like this to print array contents:
print loop
add 1 to subscript
Array-variable (subscript)
Obviously, I have had experience in other languages in doing something like this, but I don't know the specifics of using this in Crystal. Your very detailed answer is GREATLY appreciated.
What I am envisioning is something like this:
Inital set-up in sub-report
Declare array variable
Declare subscript
Read loop
READ 1st NAME in sub-report
Set subscript up by 1
move name to array variable (subscript)
After sub-report has finished for that case, I envision the formula in the main report doing something like this to print array contents:
print loop
add 1 to subscript
Array-variable (subscript)
Obviously, I have had experience in other languages in doing something like this, but I don't know the specifics of using this in Crystal. Your very detailed answer is GREATLY appreciated.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thanks guys. It looks like it is working for me. just one small issue though. I need to initialize the array each time before I load it, or else items from previous record will display.
How/where do I initialize the array??
Thanks
How/where do I initialize the array??
Thanks
You could initialize it in the subreport header.
mlmcc
mlmcc
The subreport report header should be a good place (as long as the formula that adds strings to the array is not in that section). You could do it somewhere in the main report, but exactly where would depend on where your subreport is located, and where you output the value that came from the subreport.
You'll need to reset the array and the count. Create a formula like the following and put it in the subreport report header:
WhilePrintingRecords;
Shared StringVar Array strNamesList;
Shared NumberVar intNamesListCount;
ReDim strNamesList [ 1 ];
intNamesListCount := 0;
""
Redim without Preserve will clear the contents of the array.
James
You'll need to reset the array and the count. Create a formula like the following and put it in the subreport report header:
WhilePrintingRecords;
Shared StringVar Array strNamesList;
Shared NumberVar intNamesListCount;
ReDim strNamesList [ 1 ];
intNamesListCount := 0;
""
Redim without Preserve will clear the contents of the array.
James
You could even do it in the formula that displays the list if you are done with the list at that point.
Since the building does a ReDim with the count all you really need to do is set the counter back to 0.
mlmcc
Since the building does a ReDim with the count all you really need to do is set the counter back to 0.
mlmcc
True on both counts, although if you were using Join to output the values directly from the array, as in the formula that I posted, you'd have to reset the array elsewhere, or save the array values in a variable, reset the array, and then output the variable. But, as mlmcc said, all that you really need to do is reset the counter to 0, and you could do that in a formula like mine before the Join.
James
James
ASKER
I am testing and will let you know.
Thank you
Thank you
ASKER
I will reward points for this, however, I was unable to get it to work.
Thanks
Thanks
There is no requirement to reward points if there is no solution. You can just delete the question.
mlmcc
mlmcc
As mlmcc said, you didn't have to award the points if you didn't get a solution, although you did say at one point that it was working, but you needed to re-initialize the array for each record, so it sounded like you were at least close. If you got that far, it should have been possible to get the re-initializing working.
James
James
For Index := 1 to intNamesListCount do
if strNames = "" then
strNames := strNamesList[Index]
else
strNames := strNames & chr(13) & strNamesList[Index];
James