Creating a collection of User-defined types.

Banana

split with a cherry atop.
Local time
Yesterday, 19:12
Joined
Sep 1, 2005
Messages
6,318
Okay, I'm probably missing something very obvious, but I want to use a collection to store a bunch of user-defined types.

Here's a cutdown version of what I want to accomplish:

Code:
Private Type PropertyInfo
   pName As String
   pType as String
   pValue as Variant
End Type

Private ctlProperties as Collection

Private Sub foo(ctl As Control)

Dim prp as Property
dim CtlPrp as PropertyInfo

Set ctlProperties = New Collection

For each prp in ctl.Properties
     CtlPrp.pName = prp.Name
     CtlPrp.pType = prp.Type
     CtlPrp.pValue = prp.Value

    'Add this to the collection
    [color=red]ctlProperties.Add CtlPrp, CtlPrp.Name[/color]
Next prp

End Sub

The compiler chokes on the red line saying:

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

So I changed the Type scope to public, then tried to move the Type statement from a form module (where code was originally) to a new standard module, explicitly casting my UDT to a variant with CVar(), then move the entire code, but to no avail, getting same error each time.

I really would much rather that I use a collection to store my UDTs, so any insights would be much appreciated.
 
Found the answer. Apparently, we have to use class modules or DLL to make it "public object module."

:grumble:

Why the arbitrary limitation? Why the unhelpful error message- call a spade a spade, will you, MS?

:grumble:
 

Users who are viewing this thread

Back
Top Bottom