[AccessD] Problems with Arrays

jack drawbridge jackandpat.d at gmail.com
Tue Jan 17 13:11:55 CST 2023


Arthur, based on Stuart's posts:
Sub arthur1()
Dim arrLetters() As Variant
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")

Dim ALetters() As String
Dim s As String
s = "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"
ALetters = Split(s, ",")
End Sub

On Tue, Jan 17, 2023 at 1:32 PM Arthur Fuller <fuller.artful at gmail.com>
wrote:

> 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
> --
> AccessD mailing list
> AccessD at databaseadvisors.com
> https://databaseadvisors.com/mailman/listinfo/accessd
> Website: http://www.databaseadvisors.com
>


More information about the AccessD mailing list