Make an array available to a called module

A

Andy Reed

I have some code within a form (a class object) which
calls a public module. Within the class object code I
declare an array as follows :-

ReDim n1(rc)

where rc is the number of records in a record set.

Is it possible to make this array available to the called
module. I can't make the array global as it is not
allowed. The Help file suggested using a Property object
to return a Variant but I'm not too sure about this.

Thanks,
Andy.
 
M

Marshall Barton

Andy said:
I have some code within a form (a class object) which
calls a public module. Within the class object code I
declare an array as follows :-

ReDim n1(rc)

where rc is the number of records in a record set.

Is it possible to make this array available to the called
module. I can't make the array global as it is not
allowed. The Help file suggested using a Property object
to return a Variant but I'm not too sure about this.

I don't understand, why not just pass it in an argument to
the public procedure?

Declare the public sub something like:

Public Sub SumArray(lngX() As Long) As Long

For K = LBound(lngX) To UBound(lngX)
. . .

and call it with something like this:

Dim lngA(2) As Long
lngA(0) = 1
lngA(1) = 2
lngA(2) = 3
SumArray lngA
 
A

Albert D. Kallal

Just make a property of the object that exposes the array:


So, just dim the array as private. then go:


dim strBuf(12) as string


Public Property Get pArray(intArrayValue As Integer) As String

pArray = strBuf(intArrayValue)

End Property

Public Property Let pArray(intArrayValue As Integer, strValue As string)

strBuf(intArrayValue) = lngValue

End Property


You can then go:

myclass.pArrary(5) = "hello"

debug.print myclass.pArray(5)

The above will return hello. So, all use, it is just like an array anyway.

You can also do the above for a form.
 

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