Arrays are used to store a number of values using a single name and multiple subscripts.  An array can hold anywhere from 1 to 1000 values in Crystal Reports version 8.5.  The formulas below show an example of how an array can be used to create and populate an array with a list of solicitor names.




whileprintingrecords;

stringvar array solicitors;

numbervar counter := 1;



The formula above would normally be displayed in the group header of a report and declares both the string variable array called solicitors as well as the counter variable which will be used to load the array.  As with most variables the function whileprintingrecords is used to tell the Crystal report when the values should be gathered.



whileprintingrecords;

stringvar array solicitors;

numbervar counter;



if not({Solicitors.LAST_NAME} in solicitors) then

   counter := counter + 1;

       Redim Preserve solicitors[counter];

   if not ({Solicitors.LAST_NAME} in solicitors) then

   Solicitors[counter] := {Solicitors.LAST_NAME};



This formula would normally be placed in the details section and states the variables that will be used, as well as when the formula will run.  It then determines if the value for solicitor last name already exists in the array called solicitors.  If the name isn't already in the array the counter in incremented by one.  The redim preserve function is used to tell Crystal how many values are in the array while leaving all current values already in the array alone. Lastly, this formula stores the solicitor last name in the array at the position specified by the counter.  For example, the first value in the array may be Smith.  The formula would then repeat because it is in the details section and the second value in the array would be populated by the second name, Jones.



whileprintingrecords;

stringvar array solicitors;



if solicitors[1] = "" then "" else

Join(solicitors," / ")



This formula, placed in the footer, will declare the variable again, then determine if the first value of the array is blank.  If the value is blank then a blank is displayed.  If there is a value in the array then the join operator is used to combine each value in the array and separate them with a slash.

Disclaimer: We provide programming examples for illustration only, without warranty either expressed or implied, including, but not limited to, the implied warranties of merchantability and/or fitness for a particular purpose. This article assumes you are familiar with Structured Query Language and the tools used to create and modify SQL statements and Crystal Reports. Our Customer Support may help explain the functionality of a particular procedure, but we will not modify, or assist you with modifying, these examples to provide additional functionality.


We also offer customized Crystal Report templates. To learn more about our Custom Report Solutions, contact your account manager.