Visual Basic and Visual FoxPro arrays

VBA

Dim, Redim

VFP

Dimension, Declare, Local Array

Visual Basic Syntax Notes

Visual Basic Arrays can be fixed or dynamic and their size can be changed with the ReDim statment. Unless the Option Base setting has been set to 1, VBA arrays start from zero. This declaration:

Dim myNames(10) As String

will declare an array with 11 elements from myNames(0) to myNames(10). If this use of zero as a base feels unfamiliar then you can either use Option Base 1 to force VBA to start numbering from one or you can explicitly set the range of the array:

Dimmy Names(1 To 10) As String

An array can have up to 60 dimensions but it is difficult to think of a use for such a complex structure. It's also difficult to think of a computer that could process even the smallest 60-dimensional 2x2x2x2x...x2x2x2x2 array - that's around a million Tb.

Visual FoxPro Syntax Notes

Arrays in Fox are restricted to 2 dimensions but apart from that they are very much more flexible than VBA arrays. For a start, the lack of data types in VFP means that different elements of an array can hold different types of information. The Scatter command takes advantage of this by creating an array whose elements hold the data from the fields of the current record.

FoxPro arrays are also unusual in that they can be resized at runtime without loss of data. A 6 x 6 two-dimensional array can be resized as as 12 x 2 or extended into a 3 x 5. Functions such as AElement and ASubscript allow you to refer to the elements of any array as though it were a simple list.

FoxPro makes great use of arrays. The Into Array clause in the VFP dialect of SQL creates an array holding the set of results from the query. Functions such as APrinter() and AFont() return the printers and fonts available respectively. Most of these functions start with "A" so they're easy to find in Help.

Variables  |  Language index  |  Comments