Passing collections to an object

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi,

I'm having some difficulties with some classes I set up. I'd like to have
each instance of my class "own" a dictionary object. I can set it up in the
class and work with it. My problem is in communicating it outside of the
class, or alternatively passing a dictionary object to my class either
through a method or a procedure.

I'm getting the feeling that you just can't do this. Is that true? Is
there something I'm missing? Along with this I'd like to be able to pass an
array to or from an object. Can this be done?

I'd appreciate any advice, or even some fairly definitive bad news.
 
P.S. If it's not clear from Tushar Mehta's post, yes, you can pass an
array to and from a Class. "Dim" a Class member variable as type
Variant and pass an array to it via a Property Let procedure.

Hth,
Merjet
 
I'm surprised -- I had thought I couldn't do it. I'll read through the post
tomorrow (actually later today) when I'm awake (it's 1:00 AM here). I think
this will save me a lot of effort.
 
I did have a little trouble following it, but got what I needed to work. For
what it's worth, I pasted my test code below, in case it's of any use.
Actually I think my only problem was not using "Set" where I needed it.

Thanks again for letting me know it was doable.

'---This is a regular module---
Sub main()
Dim x As New Class1
Dim y As New Class2
Dim z
Set z = CreateObject("scripting.dictionary")
x.Name = "Art"
x.Age = 54
y.C1 = x
y.add = x
Set z = y.Coll
End Sub
'---End of module---


'---This is class 1---
Dim mName As String
Dim mAge As Integer

Property Let Name(ByVal Value As String)
mName = Value
End Property
Property Get Name() As String
Name = mName
End Property

Property Let Age(ByVal Value As Integer)
mAge = Value
End Property
Property Get Age() As Integer
Age = mAge
End Property
'---End of class 1---


'---This is class 2---
Dim mC1 As Class1
Dim z

Property Let C1(ByRef Value As Class1)
Set mC1 = Value
End Property
Property Get C1() As Class1
Set C1 = mC1
End Property

Property Let add(ByRef Value As Class1)
z.add 1, Value
End Property

Property Get Coll()
Set Coll = z
End Property

Private Sub Class_Initialize()
Set z = CreateObject("Scripting.Dictionary")
End Sub
'---End of Class 2---
 

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

Back
Top