ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Placing a user defined type in a Collection (https://www.excelbanter.com/excel-programming/390486-placing-user-defined-type-collection.html)

vivmaha

Placing a user defined type in a Collection
 
Hi,

I'm trying to make a collection in which i place variables of a type that i
defined.
I keep getting an error message. What is the problem?

The error message:
"Compile error: Only user-defined types defined in public object modules can
be coerced to or from a cariant or passed to late-bound functions"

The code (and where the error is thrown):
Public Type myType
stuff As Integer
End Type

Sub main()

Dim box As Collection
Set box = New Collection

Dim myVar As myType
myVar.stuff = 1

box.Add myVar '<-THIS IS WHERE I GET THE ERROR

End Sub



vivmaha

Placing a user defined type in a Collection
 
Convert the user defined type into a class.

"vivmaha" wrote:

Hi,

I'm trying to make a collection in which i place variables of a type that i
defined.
I keep getting an error message. What is the problem?

The error message:
"Compile error: Only user-defined types defined in public object modules can
be coerced to or from a cariant or passed to late-bound functions"

The code (and where the error is thrown):
Public Type myType
stuff As Integer
End Type

Sub main()

Dim box As Collection
Set box = New Collection

Dim myVar As myType
myVar.stuff = 1

box.Add myVar '<-THIS IS WHERE I GET THE ERROR

End Sub




All times are GMT +1. The time now is 06:03 PM.

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