Database development and training for Birmingham and the midlands
Specialists in Microsoft Access and Visual Foxpro database training and development
I am happy to hear from existing clients but I am taking no new calls.
Visual Basic and Visual FoxPro arrays
VBADim, Redim |
VFPDimension, 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:
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:
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.