[AccessD] Problems with Arrays
Arthur Fuller
fuller.artful at gmail.com
Tue Jan 17 12:32:18 CST 2023
I am having problems with arrays, and specifically with passing arrays to a
function.
I have tried a couple of methods, and so far cannot determine what's wrong.
At the top of a module is an array declaration:
Dim arrLetters() as String
'Public arrLetters() as String 'doesn't work either
I even tried declaring it as a Constant, embedding the population bit right
in the Declare. That didn't work.
In a sub called Setup I try to populate arrLetters:
' arrLetters is not visible here! I don't know why.
arrLetters = Array("", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", _
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X",
"Y", "Z")
This generates an immediate Type Mismatch error.
If I declare the array within the Setup sub, it works fine:
Dim arrLetters() as String
arrLetters = Array("", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J",
"K", "L", "M", _
"N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X",
"Y", "Z")
i also have a function:
Function arrFind( arrSearchIn as Variant, vTarget as Variant) As Long
Dim i as Integer
Dim intStart as Integer, intStop as Integer, intPos
iStart = LBound(arrSearchIn)
intStop = UBound(arrSearchIn)
For i = intStart to intStop
If arrSearchin(i) = vTarget) Then
intPos = i
End If
Next
etc.
Busted again! If I try to pass in arrLetters, it still fails. I tried
changing the call to:
Function arrFind(arr() As Variant, target As Variant) As Integer
No luck either.
I am flummoxed. What am I doing wrong?
--
Arthur
More information about the AccessD
mailing list