Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default User-defined type collection in class module

I am trying to build a class module that has, among other things, a
collection consisting of items of a user-defined type. VBA is not
cooperating. Let say the type declaration is:

[Private?] Type ItemData
name as String
data1 as double
data2 as double
End Type

In the class module, I set up a collection:

Dim myCollection as New Collection

I want a method to add to the collection, so in the class module:

Sub addItem(nm as String, d1 as Double, d2 as Double)
dim item as ItemData

item.name = nm
item.data1 = d1
item.data2 = d2

myCollection.Add (item)
End Sub

If I put the type declaration in the class module w/o the "Private", an
error says I cannot define a Public user-defined type in an object
module.
If I do use "Private", or if I put the type declaration into a standard
module, it then says that only user-defined type defined in public
object modules can be passed to late-bound functions (is this what is
happening, since I'm using a Collection?)

Can this be done? If so, what's the trick? Any help is appreciated!

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 69
Default User-defined type collection in class module

Rob wrote:
I am trying to build a class module that has, among other things, a
collection consisting of items of a user-defined type. VBA is not
cooperating. Let say the type declaration is:

[Private?] Type ItemData
name as String
data1 as double
data2 as double
End Type

In the class module, I set up a collection:

Dim myCollection as New Collection

I want a method to add to the collection, so in the class module:

Sub addItem(nm as String, d1 as Double, d2 as Double)
dim item as ItemData

item.name = nm
item.data1 = d1
item.data2 = d2

myCollection.Add (item)
End Sub

If I put the type declaration in the class module w/o the "Private", an
error says I cannot define a Public user-defined type in an object
module.
If I do use "Private", or if I put the type declaration into a standard
module, it then says that only user-defined type defined in public
object modules can be passed to late-bound functions (is this what is
happening, since I'm using a Collection?)

Can this be done? If so, what's the trick? Any help is appreciated!


define ItemData as public in standard module.


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default User-defined type collection in class module

witek wrote:
Rob wrote:
I am trying to build a class module that has, among other things, a
collection consisting of items of a user-defined type. VBA is not
cooperating. Let say the type declaration is:

[Private?] Type ItemData
name as String
data1 as double
data2 as double
End Type

In the class module, I set up a collection:

Dim myCollection as New Collection

I want a method to add to the collection, so in the class module:

Sub addItem(nm as String, d1 as Double, d2 as Double)
dim item as ItemData

item.name = nm
item.data1 = d1
item.data2 = d2

myCollection.Add (item)
End Sub

If I put the type declaration in the class module w/o the "Private", an
error says I cannot define a Public user-defined type in an object
module.
If I do use "Private", or if I put the type declaration into a standard
module, it then says that only user-defined type defined in public
object modules can be passed to late-bound functions (is this what is
happening, since I'm using a Collection?)

Can this be done? If so, what's the trick? Any help is appreciated!


define ItemData as public in standard module.


Hmm. I've tried that, and it returns the same error:

"Only user-defined types defined in public object models can be coerced
to or from a variant or passed to late-bound functions"

I'm actually not sure what this error is saying. I suspect it's
because I'm using a collection, but I can't say for sure.

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
Help: Compile error: type mismatch: array or user defined type expected lvcha.gouqizi Excel Programming 1 October 31st 05 08:20 PM
"User-defined type not defined" message in Excel RW1946 Excel Discussion (Misc queries) 0 August 31st 05 12:14 PM
Workspace faux user-defined type not defined Chris S[_2_] Excel Programming 3 November 11th 04 05:51 PM
User-defined data type; Error: Only User-defined types... tiger_PRM Excel Programming 1 July 18th 04 03:32 PM
Word.Document - user defined type not defined jowatkins[_7_] Excel Programming 0 January 20th 04 08:46 AM


All times are GMT +1. The time now is 07:28 AM.

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

About Us

"It's about Microsoft Excel"