ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Strange error message when loading a collection with an item of userdefined type (https://www.excelbanter.com/excel-programming/440635-strange-error-message-when-loading-collection-item-userdefined-type.html)

deltaquattro

Strange error message when loading a collection with an item of userdefined type
 
Hi,

I want to store an unknown number of records, read from a txt data,
into a Collection. Each record is made of 26 strings, so I defined a
user-defined type Record:

Const NLines As Long = 26
Type Record
Lines(NLines) As String
End Type
Dim MyRecord As Record

I also defined a Collection object to store all the record:

Dim List As Collection
Set List = New Collection

However, when I read a record and then try to load it into List:

Data.Add Item:=MyRecord

I get this incomprehensible (for me) error message:

"Only public user defined types defined in public object modules can
be used as parameters or return types for public procedures of class
modules or as fields of public user defined types"

What's happening? Can you help me? Thanks in advance,

Best Regards

deltaquattro







aflatoon

Strange error message when loading a collection with an item of userdefined type
 

Hello,
I think your problem is that you cannot coerce the UDT to a Variant to
pass to the Add method. You may as well create your own Record class
rather than using a UDT and pass an instance of that to the collection
instead.
HTH.


--
aflatoon
------------------------------------------------------------------------
aflatoon's Profile: 1501
View this thread: http://www.thecodecage.com/forumz/sh...d.php?t=187568

http://www.thecodecage.com/forumz/chat.php


deltaquattro

Strange error message when loading a collection with an item ofuserdefined type
 
Hi aflatoon,

thank you very much, that worked! Now I can start struggling with all
the other problems concerning the UDT-to-Class migration ;) thanks
again,

Best Regards

deltaquattro

On 15 Mar, 14:56, aflatoon wrote:
Hello,
I think your problem is that you cannot coerce the UDT to a Variant to
pass to the Add method. You may as well create your own Record class
rather than using a UDT and pass an instance of that to the collection
instead.
HTH.

--
aflatoon
------------------------------------------------------------------------
aflatoon's Profile: 1501
View this thread:http://www.thecodecage.com/forumz/sh...d.php?t=187568

http://www.thecodecage.com/forumz/chat.php




All times are GMT +1. The time now is 12:23 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com