View Single Post
  #4   Report Post  
Posted to microsoft.public.excel.programming
Jon Peltier Jon Peltier is offline
external usenet poster
 
Posts: 6,582
Default Question: Can't pass an Array to a class

I sometimes put the array into a variant, and pass it that way.

- Jon
-------
Jon Peltier, Microsoft Excel MVP
Tutorials and Custom Solutions
http://PeltierTech.com
_______


"Peter T" <peter_t@discussions wrote in message
...
Hi Charles,

You can't assign an array to a Property. Instead of the property method
pass
the array as an argument of a normal function. If you particularly want to
use the Property method try adapting something like this (untested)

change
Public Property Let AddtheStuff(TheStuff() As Integer)

to
Public Property Let AddtheStuff(TheStuff() As Integer, nValue as long)

change -
MyObject.AddtheStuff = ArrVar

to
MyObject.AddtheStuff(ArrVar) = 0 ' ie some value

In passing, there's no advantage to declaring As Integer vs As Long, quite
the contrary

Regards,
Peter T

"Charles" wrote in message
oups.com...
Hello

I am struggling to pass an array to a class. Basically I defined the
class as follows:

Public xVar As Integer
Public Property Let AddtheStuff(TheStuff() As Integer)
Dim i As Integer
For i = LBound(TheStuff) To UBound(TheStuff)
xVar = xVar + TheStuff(i)
Next i
End Property


and I tested the array with the following procedu

Sub TestTheObject()
Dim MyObject As TheObject
Set MyObject = New TheObject
Dim ArrVar(1 To 10) As Integer
Dim i As Integer
For i = 1 To 10
ArrVar(i) = 10 * i
Next i
MyObject.AddtheStuff = ArrVar
MsgBox MyObject.xVar
End Sub

I always end up with the same compilation error: can't assign an
array. Am I doing something wrong?

Thanks in advance for your help
Charles