Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.
Array Manipulation
FoxPro has quite a few functions for working with arrays; all of them begin with the letter “A” (we don’t think it’s scarlet, though). These functions can be loosely divided into various groups.
The first group is simply for working with an array itself. This group includes ACOPY()
, ADEL()
, AELEMENT()
, AINS()
, ALEN()
, ASCAN()
, ASORT()
and ASUBSCRIPT()
.
Next, we have functions that collect information about the general environment and store it in an array. These are ADIR()
, AERROR()
, AGetFileVersion()
, AFONT()
, AMouseObj()
and APRINTERS()
.
The third group gathers information about the data environment and stores it in an array. These functions are ADATABASES()
, ADBOBJECTS()
, AFIELDS()
and AUSED()
.
The last group is a set of functions that put information about objects (the OOP kind of objects) into an array. In this group, we find AClass()
, AGetClass()
, AINSTANCE()
, AMEMBERS()
, ASELOBJ()
, and AVCXClasses()
.
Finally, we have one function that doesn’t fit into any of the other groups—ALINES()
.
Here’s a list of the various array functions with a quick description of each so you can figure out which one to go look up.
Function |
Description |
AClass() |
Fills array with class hierarchy for object. |
ACOPY() |
Copies from one array to another. |
ADatabases() |
Fills array with list of open databases. |
ADBObjects() |
Fills array with contents of database. |
ADEL() |
Deletes items from array. |
ADIR() |
Fills array with list of files. |
AELEMENT() |
Converts (row, column) format to element format. |
AError() |
Fills array with error information. |
AFIELDS() |
Fills array with field list. |
AFONT() |
Fills array with font information. |
AGetClass() |
Lets the user choose a class and returns info about the class in an array. |
AGetFileVersion() |
Fills array with version information for an EXE or DLL. |
AINS() |
Inserts items into array. |
AInstance() |
Fills array with instances of object. |
ALEN() |
Computes size of array. |
ALines() |
Fills array with the lines of a character string. |
AMembers() |
Fills array with members of object. |
AMouseObj() |
Fills array with information about mouse position. |
APrinters() |
Fills array with list of printers. |
ASCAN() |
Finds item in array. |
ASelObj() |
Fills array with selected objects. |
ASORT() |
Sorts array. |
ASUBSCRIPT() |
Converts element format to (row, column) format. |
AUsed() |
Fills array with list of tables in use. |
AVCXClasses() |
Fills array with information about classes in a class library. |
All the functions except the first group have a lot in common. They all go out, find something out, and stick the results into an array. They all handle the array similarly. If it doesn’t exist, they create it. If it does exist and it’s the wrong size, they resize it. If the array exists and the function doesn’t return anything for some reason, they leave the array as it was. Almost all of these functions return the number of rows in the resulting array.
For information about the structure of FoxPro’s arrays, see “DBC, DBF, FPT, CDX—Hike!” in “Wow, What a Concept!” Creating and resizing arrays is discussed under DIMENSION.
Although FoxPro’s implementation of arrays is pretty good and works reasonably fast, do keep in mind that this is, after all, a database management system, and that in many cases, it just makes more sense to use a table or cursor. Also, some operations are much easier with a spreadsheet than with any DBMS. Nonetheless, we do think arrays are pretty cool and we use them a fair amount.