Setting Default Values in Arrays in FoxPro

ID: Q89663

The information in this article applies to:

The DECLARE command has the same function and syntax as the DIMENSION command. The text below describes how to use these commands to specify a default value for an array.

DECLARING AN ARRAY

DECLARE <ARRAYNAME>[<NUMBER OF ELEMENTS>] DECLARE <ARRAYNAME>(<NUMBER OF ELEMENTS>)

Examples

   DECLARE NAME[10]

This example declares a one-dimensional array that contains ten elements.

   DECLARE NAME(10,2)

This example declares a two-dimensional array that contains two columns of ten elements each.

DIMENSIONING AN ARRAY

DIMENSION <ARRAYNAME>[<NUMBER OF ELEMENTS>] DIMENSION <ARRAYNAME>(<NUMBER OF ELEMENTS>)

Examples

   DIMENSION NAME(10)

This example declares a one-dimensional array that contains ten elements.

   DIMENSION NAME[10,2]

This example declares a two-dimensional array that contains two columns of ten elements each.

The DECLARE and DIMENSION commands can create one-dimensional and two-dimensional arrays of memory variables.

Each array uses one memory variable for overhead and is limited to a maximum of 3600 elements in the Standard version of FoxPro and 65,000 elements in the Extended version of FoxPro. Sufficient memory to allocate space to store the array is required.

The elements of a memory variable array can contain any data type. Each array element is initialized to the logical value .F. when it is first declared or dimensioned.

The DECLARE AND DIMENSION commands support both square brackets and parentheses to delimit the number of elements. An array that is created in the Command window is automatically declared PUBLIC, while an array created in a program is declared PRIVATE by default. An application can use the PUBLIC command to make an array public.

INITIALIZING AN ARRAY

The two techniques demonstrated in the following examples can be used with two-dimensional arrays as well as one-dimensional arrays:

To remove the values from an array, use an expression to set the value of each element to the logical value .F., for example:

   NAME=.F.

Additional reference words: FoxDos FoxWin 2.00 clearing setting 2.50 2.50a KBCategory: kbenv kbprg KBSubcategory: FxenvMemory

Last Reviewed: June 27, 1995