Scan an Array

P

Phil

Im trying to write a function:
Function aScan(
p_ArrayName,
eExpression As Variant,
Optional nStartElement As Integer,
Optional nElementsSearched,
Optional nSearchColumn) as integer

to Search an array for an element containing the same data
and data type as an expression.

Since I don't know how big the array is, or how many
dimensions it has, I can't simply do the following:

aScan = -1
For i = int_lBound To int_uBound - 1
If p_ArrayName(i) = eExpression Then
aScan = i
End If
Next

I have the sense that I should try to ReDim the array;
scan it as 1 dimension as above, and then ReDim it back.
Is this a correct approach or is there some simpler way?

If this function is a correct approach, it seems like it
should be one of the foundations for my array
manipulations in Access.
If not, advice or direction on generic array manipulations
would be helpful.
Thanks for your help.

Phil
 
L

Larry Linson

I'd think the simplest way would be to use the LBound and UBound functions
to determine how big it is. Unless I am mistaken, however, you cannot pass
an array as a procedure argument unless you use the ParamArray keyword (see
help for limitations), or store the whole array in a Variant. In either of
these cases, the LBound and UBound functions should work nicely.

Larry Linson
Microsoft Access MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top