Search code examples
vbavb6user-defined-types

User Defined Type (UDT) as parameter in public Sub in class module (VB6)


I've tried to solve this problem, but can't find any solution. I have a UDT defined in a normal module, and wanted to use it as parameter in a Public Sub in a Class Module. I then get a compile error:

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

I then try to move my UDT in the class, declared as Private. I get this compile error:

Private Enum and user defined types cannot be used as parameters or return types for public procedures, public data members, or fields of public user defined types.

I finaly try to declare it as Public in the class, and get this compile error:

Cannot define a Public user-defined type within a private object module.

So is there any way to have a public UDT used as a parameter in a public sub in a class?


Solution

  • So is there any way to have a public UDT used as a parameter in a public sub in a class?

    In a word, no. The closest you can come with just Classic VB code would be to create a class that replicates the UDT and use that instead. There are definitely advantages there, but you're hosed if you need to pass that to, say, an API as well.

    Another option is to define the UDT in a typelib. If you do that, it can be used as a parameter for a public method.