Share via


Array Data Types (Basic Syntax)

Arrays in Crystal Reports are ordered lists of values that are all of the same type. These values are known as the array's elements. The elements of an array can be any simple type or range type. One way to create an array is using the Array function.

Arrays are most useful when used with variables. Using variables, you can change the individual elements of an array and resize the array to accommodate more elements. This capability significantly expands the capabilities of the formula language to do complex calculations.

For example, you can accumulate database field values into a global array variable in a detail level formula, and then use a formula in a group footer to perform a calculation based on those values. This allows you to perform a wide variety of customized summary operations.

Examples

An array of three Number values. The first element is 10, the second is 5 and the third is 20.

Array (10, 5, 20)

An array of seven String values:

Array ("Sun", "Mon", "Tue", "Wed", "Th", "Fri", "Sat")

An array of two DateTime Range values:

Array (#Jan 1, 1998# To #Jan 31, 1998#, _
       #Feb 1, 1999# To #Feb 28, 1999#)

You can extract individual elements out of an array using parentheses containing the index of the element you want. This is called subscripting the array:

Array (10, 5, 20) (2) ' = 5

Note

Arrays in Basic syntax are indexed from 1 (this means the first element has index 1). This is unlike in Visual Basic where arrays are indexed from 0 by default. However, in Visual Basic, arrays can be indexed from 1 by using the Option Base statement.

Number ranges can also be used to subscript arrays. The result is another array. For example:

Array (10, 5, 20) (2 To 3) ' = Array (5, 20)