• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1300
  • Last Modified:

Crystal Reports Array redim preserve not working?

I have three sub reports that run in 'details a' section.  each sub report pulls data using a different account number and adds the account number and the data to an array which is using a redim preserve syntax to save the data written to it when the next subreport writes data to the array.  Next, The main subreport in the 'details b' section that runs after all subreports in the 'details a' section has all of the fields that get printed out on the report. One of those fields is the period ytd formula which takes the data in the array and prints it to the report where the account number in the array matches the account number in the record that crystal is currently processing.  While the code is partially working in that I am getting the correct data for the last account number (record) printed on the report. I'm missing the data for all previous records.  I've increased the size of the array to make crystal produce an error so that the formula editor pops up with debuging information which is showing all three elements in the array have been correctly added.  The code below takes and splits the array (element) so that I can get the account number in one variable and the ytd data in another.  I thought perhaps that something with the redim preserve statement is not working properly.

Thank you


WhilePrintingRecords;
Shared StringVar Array PeriodYTDArray;
Shared NumberVar PeriodYTDArrayIndex;
NumberVar PeriodYTD := 0;

NumberVar Index := 0;

(While Index < PeriodYTDArrayIndex do
    Index := Index + 1;    
    StringVar AccountNumber := Split(PeriodYTDArray[Index], ":")[1];
   
    if Trim({GLMain.AccountNumber}) = Trim(AccountNumber) then
      PeriodYTD := ToNumber(Split(PeriodYTDArray[Index], ":")[2]);

);

0
MFRMLS_IT
Asked:
MFRMLS_IT
  • 3
  • 2
1 Solution
 
mlmccCommented:
Going to need to see the report or all the formulas.

That formula doesn't change the array.

mlmcc
0
 
MFRMLS_ITAuthor Commented:
The following code runs in all sub reports in 'details a'.  The only difference is the account number ("300200100:") which changes per sub report.

WhilePrintingRecords;
Shared StringVar Array PeriodYTDArray;
Shared NumberVar PeriodYTDArrayIndex;
PeriodYTDArrayIndex := PeriodYTDArrayIndex + 1;
Redim Preserve PeriodYTDArray[PeriodYTDArrayIndex];
PeriodYTDArray[PeriodYTDArrayIndex] := "300200100:" + ToText({GLMain.AccountNumber});

0
 
mlmccCommented:
You may need to put each subreport into its own section to ensure they execute separately, and to ensure the variables update correctly.

mlmcc
0
Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

 
MFRMLS_ITAuthor Commented:
proposed solution did not solve problem.
0
 
mlmccCommented:
Why did you accept the comment as the solution?

mlmcc
0
 
James0628Commented:
Sorry I didn't notice this before, but mlmcc was trying to help you (so you were in good hands) and, to be honest, I just didn't look that closely.

 You said in your first post "I am getting the correct data for the last account number (record) printed on the report".  That is correct.

 The formula in your first post uses a While loop to go through PeriodYTDArray and assign the first part (before the ":") of each element to AccountNumber, and (if that account number matches the one in the current record) the second part (after the ":") of each element (converted to a number) to PeriodYTD.

 The thing is, AccountNumber and PeriodYTD are simple variables.  Each of them can only have one value.  And there is nothing to to stop your while loop.  Every time that formula is evaluated, it will go through the entire loop.  So, at the end of that formula, AccountNumber will _always_ have the value from the last element in the array (PeriodYTDArrayIndex), and PeriodYTD will _always_ have the value from the last element where the account number matched the account number in the current record.

 There is nothing there that will output any of the other values in the PeriodYTDArray array.

 As a test, try a formula like this:

Shared StringVar Array PeriodYTDArray;
Join (PeriodYTDArray, ChrW (10))


 That should just join the string array into one long string, but with a line feed in between the elements.  Put that formula on the report and set the "Can grow" option in the field format, and you should see all of the values that are actually in that array.

 Assuming that the values are there, can you explain what you were trying to do with that first formula?

 James
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now