Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 29
Default Unable to add user-defined data types to a collection

Hi,

I am adding a user-defined data type to a collection as illustrated below
but failed ... Can somone please help? Thanks..


'All codes here are written in a module "ErrSeeder"
'--------------------------------------
(General) (Declarations)
Type Seed
name as string
no as integer
End Type
'--------------------------------------
Sub test()

Dim c As New Collection
Dim s As Seed
s.Name = "Watermelon Seed"
s.no = 1

c..Add s <- Compliation fail at this point with the following error :
Only user-defined types defined in public object modules can be coerced to
or from a variant or passed to late-bound functions

End Sub
'--------------------------------------
May I know where can I define my user data type so that the code above will
work ? What does it mean by public object modules ?

Thanks.

Regards,
Adrian


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Unable to add user-defined data types to a collection

Hi Adrian,

You can only add objects to collections, not user defined types :-(

Create a small class object and add that to the collection and you should be
fine.

HTH

Peter Beach

"Adrian" wrote in message
...
Hi,

I am adding a user-defined data type to a collection as illustrated

below
but failed ... Can somone please help? Thanks..


'All codes here are written in a module "ErrSeeder"
'--------------------------------------
(General) (Declarations)
Type Seed
name as string
no as integer
End Type
'--------------------------------------
Sub test()

Dim c As New Collection
Dim s As Seed
s.Name = "Watermelon Seed"
s.no = 1

c..Add s <- Compliation fail at this point with the following error

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

End Sub
'--------------------------------------
May I know where can I define my user data type so that the code above

will
work ? What does it mean by public object modules ?

Thanks.

Regards,
Adrian




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 593
Default Unable to add user-defined data types to a collection

"Peter Beach" wrote ...

You can only add objects to collections


That's not correct:

Sub test2()
Dim c As New Collection
Dim s As String
Set c = New Collection
s = "Text"
c.Add s
End Sub

Jamie.

--
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 70
Default Unable to add user-defined data types to a collection

Hi James,

You are correct. You can also add simple data types to a collection. What
you can't add to a collection is a user-defined type.

Regards,

Peter Beach

"Jamie Collins" wrote in message
om...
"Peter Beach" wrote ...

You can only add objects to collections


That's not correct:

Sub test2()
Dim c As New Collection
Dim s As String
Set c = New Collection
s = "Text"
c.Add s
End Sub

Jamie.

--



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
Standard chart types over-ridden by user-defined 'default' SWRDA man Charts and Charting in Excel 1 November 3rd 08 12:12 AM
Save user-defined chart types in a shared Excel template? graphicslady Charts and Charting in Excel 7 September 7th 06 02:07 PM
How do I share User-Defined Custom Chart Types in Pivot Charts? jantz_question Charts and Charting in Excel 0 September 20th 05 01:39 PM
User defined data type augustus108 Excel Programming 1 April 10th 04 05:11 PM
Macros and User Defined Data Strucures Tscher Excel Programming 0 February 9th 04 10:49 AM


All times are GMT +1. The time now is 04:22 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"