Setting Default Values in Arrays in FoxPro

Last reviewed: June 27, 1995
Article 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 <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:

  • Use the STORE command to initialize the entire array of values or any element of the array. For example:

          STORE "TEST" to NAME
    

    This example initializes each element of the NAME array to the value "TEST."

          STORE "TEST" TO NAME(1)
    

    This example initializes only the first element of the NAME array to "TEST."

  • Use an expression to initialize the entire array of values or any element of the array. For example:

          NAME="TEST"
    

    This example initializes each element of the NAME array to the value "TEST."

          NAME(1)="TEST"
    

    This example initializes only the first element of the NAME array to "TEST."

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


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: June 27, 1995
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.