Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Collection Code

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.
  #2   Report Post  
Posted to microsoft.public.excel.programming
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.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 71
Default Collection Code

I have a new related problem. If I try to unload UserForm1 I get an Object
Required Error when I try to load the UserFormModelListDisplay form.
Apparently the objects in the collection are always tied to the UserForm1. I
would like to be able to unload and use the form elsewhere without losing the
collection.

How do I go about this?

Thanks


"Chip Pearson" wrote:

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.




Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
data collection driller Excel Discussion (Misc queries) 1 October 13th 09 01:04 AM
code to add a name to the names collection and assign a reference keithb Excel Programming 2 August 5th 05 06:38 AM
Collection Todd Huttenstine Excel Programming 4 December 17th 04 09:41 PM
Collection Variable Todd Huttenstine Excel Programming 4 August 14th 04 05:32 PM
sheet collection Tom Ogilvy Excel Programming 0 October 28th 03 03:15 PM


All times are GMT +1. The time now is 10:37 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"