Using Type in collection

  • Thread starter Thread starter Roy Goldhammer
  • Start date Start date
R

Roy Goldhammer

Hello there

Before short time it i wanted to use dinamic array of strings i used Redim
Preserve for this

Now i've learned new way using collection. which is mutch better way as i
see it

Now i have also an array of user defined type i've created by my self.

Is there a way to use collection in this way two?




--
øåòé âåìãäîø
ù.î. òúéã äðãñú úåëðä
(e-mail address removed)
èì: 03-5611606
ôìà' 050-7709399
 
Hi Roy,

You need to define a Class instead of a Type. For example, create a new
class module, save it as clsTest, and paste this code into it:

Option Compare Database
Option Explicit

Dim m_Name As String

Property Let Name(S As String)
m_Name = S
End Property

Property Get Name() As String
Name = m_Name
End Property

Then paste this procedure into another module and run it:

Sub TestClass()
Dim T As clsTest
Dim C As New Collection

Set T = New clsTest
T.Name = "Smith"
C.Add T, "A"

Set T = New clsTest
T.Name = "Jones"
C.Add T, "B"

Debug.Print C("A").Name
Debug.Print C("B").Name
End Sub
 
Back
Top