Thread: Collection Code
View Single Post
  #2   Report Post  
Posted to microsoft.public.excel.programming
Chip Pearson Chip Pearson is offline
external usenet poster
 
Posts: 7,247
Default Collection Code

Since you are adding Class objects to your Collection, you need
to get a property of the class in your code that adds to the list
box.

The line
UserFormModelListDisplay.ListBox1.AddItem mItem
should be
UserFormModelListDisplay.ListBox1.AddItem mItem.property

where 'property' is the desired property of the mItem class
instance.

--
Cordially,
Chip Pearson
Microsoft MVP - Excel
Pearson Software Consulting, LLC
www.cpearson.com




"Cody" wrote in message
...
I created a collection based on the code in the thread titled
"Class Instance
Identifier". On my Sheet1 I have a command button
CommandButtonMainAddaModel
that starts a UserForm UserForm1. UserForm1 has a textbox
TextBox1 and two
command buttons CommandButtonAddModel and
CommandButtonCancelAddModel. The
CommandButtonAddModel calls AddModeltoCollection from Module1.

Sub AddModeltoCollection()

Dim clsVar As Class1

Set clsVar = New Class1
clsVar.Model = UserForm1.TextBox1.Value
StoreObject clsVar, clsVar.Model

End Sub

Sub StoreObject(cObject As Class1, sName As String)

If modelClass Is Nothing Then
Set modelClass = New Collection
End If

modelClass.Add cObject, sName
End Sub

Class1 has several properties including Model which is the key
property.

I am trying to display the list of Model key names in a listbox
in a new
form called UserFormModelListDisplay. Thread titled Object
Required Error
8/22/05 is related to my problem. I have a type mismatch in
the following
code trying to AddItem the Model properties to the ListBox1.
See the
following code. Also it appears that the collection is lost
when UserForm1
is unloaded. This may or may not be the case as I have not
been able to
successfully list the property.

Private Sub UserFormModelListDisplay_Initialize()

Dim mItem As Variant

Load UserFormModelListDisplay
For Each mItem In modelClass
UserFormModelListDisplay.ListBox1.AddItem mItem
Next mItem
UserFormModelListDisplay.Show

End Sub

Any help here would be greatly appreciated.