Microsoft KB Archive/89663

{| = Setting Default Values in Arrays in FoxPro =
 * width="100%"|

ID: Q89663

The information in this article applies to:


 * Microsoft FoxPro for MS-DOS, versions 2.0, 2.5, and 2.5a
 * Microsoft FoxPro for Windows, versions 2.5 and 2.5a

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 [] DECLARE ()

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 [] DIMENSION ()

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:

  Use the STORE command to initialize the entire array of values or any element of the array. For example: STORE &quot;TEST&quot; to NAME This example initializes each element of the NAME array to the value &quot;TEST.&quot; STORE &quot;TEST&quot; TO NAME(1) This example initializes only the first element of the NAME array to &quot;TEST.&quot;   Use an expression to initialize the entire array of values or any element of the array. For example: NAME=&quot;TEST&quot; This example initializes each element of the NAME array to the value &quot;TEST.&quot; NAME(1)=&quot;TEST&quot; This example initializes only the first element of the NAME array to &quot;TEST.&quot; 

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
 * }