Scan an Array

  • Thread starter Thread starter Phil
  • Start date Start date
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
 
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
 
Back
Top