I think you're looking to create a collection class something like the
following
' *************************************
' Class module called MyBooks
' *************************************
Option Compare Database
Option Explicit
Private m_MyBooks As Collection
' ************************************
'
Private Sub Class_Initialize()
Set m_MyBooks = New Collection
End Sub
Private Sub Class_Terminate()
Do Until m_MyBooks.Count = 0
Call m_MyBooks.Remove(1)
Loop
Set m_MyBooks = Nothing
End Sub
Function Add(Name As String, Number As Integer) As MyBook
Dim mb As MyBook
Set mb = New MyBook
With mb
.mystring = Name
.mynumber = Number
End With
m_MyBooks.Add mb, Name
Set Add = m_MyBooks(Name)
Set mb = Nothing
End Function
Function Count() As Integer
Count = m_MyBooks.Count
End Function
Function Item(Index) As MyBook
Set Item = m_MyBooks(Index)
End Function
Sub Remove(Item)
m_MyBooks.Remove Item
End Sub
' *************************************
' Class module called MyBook
' *************************************
Option Compare Database
Option Explicit
Public mystring As String
Public mynumber As Integer
' *************************************
' Test code in standard module
' *************************************
Function mBooks()
Dim mbs As MyBooks
Dim mb1 As MyBook
Dim mb2 As MyBook
Dim mb3 As MyBook
Set mbs = New MyBooks
Set mb1 = mbs.Add("a", 1)
Set mb2 = mbs.Add("b", 2)
Set mb3 = mbs.Add("c", 3)
Debug.Print "From the Add method"
Debug.Print "--------------------"
Debug.Print mb1.mystring, mb1.mynumber
Debug.Print mb2.mystring, mb2.mynumber
Debug.Print mb3.mystring, mb3.mynumber
Debug.Print
Set mb1 = Nothing
Set mb2 = Nothing
Set mb3 = Nothing
Set mb1 = mbs.Item(1)
Set mb2 = mbs.Item(2)
Set mb3 = mbs.Item(3)
Debug.Print "From the Item Index"
Debug.Print "--------------------"
Debug.Print mb1.mystring, mb1.mynumber
Debug.Print mb2.mystring, mb2.mynumber
Debug.Print mb3.mystring, mb3.mynumber
Debug.Print
Set mb1 = Nothing
Set mb2 = Nothing
Set mb3 = Nothing
Set mb1 = mbs.Item("a")
Set mb2 = mbs.Item("b")
Set mb3 = mbs.Item("c")
Debug.Print "From the Item Key"
Debug.Print "--------------------"
Debug.Print mb1.mystring, mb1.mynumber
Debug.Print mb2.mystring, mb2.mynumber
Debug.Print mb3.mystring, mb3.mynumber
Set mb1 = Nothing
Set mb2 = Nothing
Set mb3 = Nothing
Set mbs = Nothing
End Function
--
Terry Kreft
"Larry" <do********@nospamhere.com> wrote in message
news:FG***************@news.uswest.net...
so if I want to make a collection of objects this class
Public Class MyBook
public mystring as string
public mynumber as integer
end class
i want to a collection of mybook.
and I want to be able to dynamically add to the collection. I also want
to retrieve from the collection based on "mystring". so how do you do
that?
*** Sent via Developersdex http://www.developersdex.com ***