[AccessD] Problems with Arrays

Arthur Fuller fuller.artful at gmail.com
Tue Jan 17 13:34:23 CST 2023


Thanks, Jack, that works but doesn't answer my question. You are just
making a local copy, rather than referencing an array declared at the top
of the module. I don't want to have to repeat your strategy in a dozen
functions. That defeats the purpose.

The arrays are declared outside of the subs and functions. They are
declared Private, which in this context means local to this module. This
certainly works with normal variables (ints, strings, bools).  But I seem
unable to make it work.

One question, before I load my revolver and do something stupid... Can a
function return an array? If so, I can work with that and get where I need
to go.

On Tue, Jan 17, 2023 at 2:12 PM jack drawbridge <jackandpat.d at gmail.com>
wrote:

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


-- 
Arthur


More information about the AccessD mailing list