[AccessD] Array questions

Stuart McLachlan stuart at lexacorp.com.pg
Mon Jan 16 18:09:30 CST 2023

On 16 Jan 2023 at 18:16, Arthur Fuller wrote:

> 1. How can I dimension an array to a given size?

 DIM myArray( 1 to 10) AS STRING

> 2. How to search an array for a given element? (Returning the element
> number or 0 if not found)

Dim lArrPtr as Long
DIm i as long
For i = LBound(myArray()) to UBOUND(myArray)
If myArray(i) = sTestString then l = i

 3. How to determine the length of an array?

You mean the number of elements? 
UBOUND(myArray) - LBOUND(myArray) + 1

> 4. Can I prefill an array when I declare it, I.e. fill it with zeroes
> on the same line as its Dim? 

You have to do it in two steps.
Nor can you assign a collection of values to multiple array elements. in one statement.

A numeric array is autofilled with zero, a string array is "autofilled" with  zero length strings.
If you want to populate then with anything else, you can do it in a loop

For i = LBound(myArray()) to UBOUND(myArray)
myArray(i) = " "

5. Given 2 arrays of equal length, can I
> create a 2D array with 2 rows and assign an array to each? 

You can create an array with two COLUMNS

> Given two arrays a1 and a2, both populated;

For i = LBound(myArray()) to UBOUND(myArray)
    a3(i,1) = a1(i)
    a3(i,2) = a2(i)

> Dim a3( a1, a2)
> Why not?

Because that is nonsense? That's not what DIM does.

More information about the AccessD mailing list