Crystal Reports - Creating Arrays

An Array variable in Crystal Report can be defined by using a keyword “Array”.

Global NumberVar Array Z := [1, 2, 3];

You can also assign values to the elements of Array and these values can be used for computations in formulas. For example −

StringVar Array Z := [“Hello”,”World”];
Z[2] :=[“Bye”];
UpperCase (Z [2] )

This formula will return the string “Bye”.

You can also resize Array using Redim and Redim Preserve keywords. Redim is used to remove previous entries of an Array while resizing it, and Redim Preserve is used to contain previous Array values. For example

Local NumberVar Array Z;
Redim Z [2]; //Now Z is [0, 0]
Z [2] := 10; //Now Z is [0, 10]
Redim Z [3]; //Now Z is [0, 0, 0], Redim has erased previous Array values.
Z [3] := 20; //Now Z is [0, 0, 20]
Redim Preserve Z [4]; 
//Now Z is [0, 0, 20, 0], Redim Preserve has contained previous Array values.

Array with Loops

Arrays are also used with Loops: like For loop.

Local NumberVar Array Z;
Redim Z[10];
Local NumberVar x;
For x := 1 To 10 Do
(Z[x] := 10 * x);
Z [5] //The formula returns the Number 50
Kickstart Your Career

Get certified by completing the course

Get Started