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
 

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

Similar Threads

Get Data from source safe 4
Merging two Tif files to one file 5
error 3709 3
Waiting for finish Shell Function 1
Using Class Module 5
Using MODI on access 1
Reading Text File 1
Using Format for textboxes 1

Back
Top