View Full Version : UDT/Class Coding Problems


BCL
08-21-2006, 01:34 PM
I am using VB Editor 6.0 (from excel) and I need to create a public user defined type that can be passed to a subroutine.

Example:

Public Type mytype

n as integer
qty(20) As Integer

End Type

Sub test()

dim clst(5) as mytype

call test2(clst) 'error here

end sub

sub test2(clst)

clst.n=1

end sub

When I try to pass the UDT to a sub I get the error:

"only user defined types in public object modules can be coerced to or from a variant or passed to late bounding functions"


So I tried to create a class module with the following code:

Public n as integer
Public qty(20) As Integer

Then in a normal module I have the code:

Sub test()

dim clst(5) as new class1

call test2(clst)

end sub

sub test2(clst)

clst.n=1

end sub

This will work fine if I don’t have the array in the class module but with the array I get the error

"Constants, fixed length strings, arrays, user defined types and declare statements not allowed as public members of object modules"


Can anyone help me please?