Partager via


Arrays

An array is an ordered series of data values, which are called array elements. Array elements are referenced by their position in the array, which are numbers called array subscripts or indexes. Because arrays exist in memory, you can quickly and easily specify, access, and manipulate data elements in an array. A Visual FoxPro array can contain any or all types of data as elements. Arrays have the same scoping options as variables.

You can create an array using the DIMENSION or DECLARE command and assign a value to each element by specifying the element using the array name and the element's position, or subscript. You can use the SCATTER, GATHER, COPY TO ARRAY, and APPEND FROM ARRAY commands to move field values to and from array elements.

For example, the following line of code creates a two-dimensional array of five rows and two columns, then assigns a value to the second column of the first row:

DIMENSION ArrayName[5,2]
ArrayName[1,2] = 966789

Note

Visual FoxPro arrays are one-based - the first element, row, or column of an array is specified with the number 1. (Arrays in other programming languages may be zero-based; the first element, row, or column of an array is specified with the number 0.)

For more information, see DIMENSION Command, DECLARE Command, SCATTER Command, GATHER Command, COPY TO ARRAY Command, and APPEND FROM ARRAY Command. For more information about using arrays in your application, see Data Transfer and Arrays.

See Also

Reference

Visual FoxPro System Capacities

Data Storage Containers

Variables (Visual FoxPro)