Storage Mode > Using the XArrayDB Object > Redimensioning an XArrayDB object |
Before an XArrayDB object can be used, you must define its dimensions in code with the ReDim method, which is similar to its counterpart in Visual Basic. For example, the following line of code sets up a two-dimensional array with 20 rows (indexed from 1 to 20) and 4 columns (indexed from 0 to 3):
Example Title |
Copy Code
|
---|---|
MyArray.ReDim 1, 20, 0, 3 |
You can use the Count property to determine the number of elements in a given dimension:
Example Title |
Copy Code
|
---|---|
' Prints 20. Debug.Print MyArray.Count(1) ' Prints 4. Debug.Print MyArray.Count(2) |
Note that the index passed to the Count property is one-based. To determine the valid indexes for a given dimension, you can use the LowerBound and UpperBound properties:
Example Title |
Copy Code
|
---|---|
' Prints 1. Debug.Print MyArray.LowerBound(1) ' Prints 20. Debug.Print MyArray.UpperBound(1) ' Prints 0. Debug.Print MyArray.LowerBound(2) ' Prints 3. Debug.Print MyArray.UpperBound(2) |
When an XArrayDB object is connected to a TDBGrid or TDBDropDown control, its first dimension always specifies the row index from the grid's perspective. Or, to put it another way, the set of allowable bookmarks ranges from LowerBound(1) to UpperBound(1).
Likewise, the second dimension of an XArrayDB object always specifies the column index from the grid's perspective. Or, to put it another way, the grid addresses data columns in the XArrayDB object using indexes that range from LowerBound(2) to UpperBound(2). Therefore, if your application manipulates columns in code, it is a good idea to make the second XArrayDB dimension zero-based instead of one-based. That way, you can use the same indexes to refer to both grid columns and XArrayDB columns.