User Defined Type / vb6
hi, i got a compile error that says :
"Only PUBLIC defined types defined in PUBLIC object module can be used as Parameters or return types for public procedures of class modules or as fields of public user defined types"
Ok! How do I get my User defined type to be accepted as a parameter or a return type in my class module?
Place "Public" in front of it? Move it into a .BAS file that''s defined as public?
Toolmaker
Toolmaker
All bas file are defined as public when you create it.
When I use a define type as parameter in a function or procedure I write the type definition in the bas file
When I use a define type as parameter in a function or procedure I write the type definition in the bas file
When you use public classes in VB, your classes, parameters, and return values have to abide by the rules of the ActiveX/COM object model, as it is this model which VB uses as its object model.
Therefore you cannot pass user defined types as parameters to public object methods or functions. A workaround is to wrap your user defined type in a class, and pass the object instance of the class instead, VB/ActiveX/COM is quite happy about passing other VB/ActiveX/COM objects around.
Therefore you cannot pass user defined types as parameters to public object methods or functions. A workaround is to wrap your user defined type in a class, and pass the object instance of the class instead, VB/ActiveX/COM is quite happy about passing other VB/ActiveX/COM objects around.
The workaround I have already mentioned, wrapping your user defined type (UDT) in a class, with object properties wrapping UDT members, works for VB5 and VB6.
I just discovered that VB6 introduced another workaround whereby you can just place your UDT in an existing class file, make it public, and you can the pass it to object functions. This is not the same as a public UDT in BAS module. I think that behind the scenes VB6 must wrap up your class defined public UDT as a COM object.
I just discovered that VB6 introduced another workaround whereby you can just place your UDT in an existing class file, make it public, and you can the pass it to object functions. This is not the same as a public UDT in BAS module. I think that behind the scenes VB6 must wrap up your class defined public UDT as a COM object.
I just got the same problem, but a found another workaround. Appenrently, microsoft as issued a service pack to vb6 that fixes the problem. I''m about to install the service pack right know. You can go here http://support.microsoft.com/default.aspx?scid=kb;EN-US;224185 if you want to check it out and download the service pack.
Good luck
Good luck
Well ... i''m back after the update and sadly ... it didn''t work. That may be in part cause read to fast. The link isn''t exactly what where actually search for ... so never mind.
Hi, I find how you can use a user defined type as a return type, the secret is in this little piece of code:
module: "Type_Def"
''--Type definition-------------------------------------
Public Type Test_type
A as integer
B as string
End Type
class: "Class_Def"
''--Property definition---------------------------------
''--DECLARE THE PROPERTY AS "FRIEND" INSTEAD "PUBLIC"!--
Friend Property Get Test_Prop() as Test_Type
Dim Foo as Test_Type
Foo.A = 0
Foo.B = "Hi"
Test_Prop = Foo
End Property
test form:
''--Create the Object-----------------------------------
Private O as New Class_Def
Private Sub Form_Load()
Dim i as Test_Type
i=O.Test_Prop
if i.A = 0 then MsgBox i.B
End Sub
Good Luck and have a nice day!!
angelsergio@hotmail.com
module: "Type_Def"
''--Type definition-------------------------------------
Public Type Test_type
A as integer
B as string
End Type
class: "Class_Def"
''--Property definition---------------------------------
''--DECLARE THE PROPERTY AS "FRIEND" INSTEAD "PUBLIC"!--
Friend Property Get Test_Prop() as Test_Type
Dim Foo as Test_Type
Foo.A = 0
Foo.B = "Hi"
Test_Prop = Foo
End Property
test form:
''--Create the Object-----------------------------------
Private O as New Class_Def
Private Sub Form_Load()
Dim i as Test_Type
i=O.Test_Prop
if i.A = 0 then MsgBox i.B
End Sub
Good Luck and have a nice day!!
angelsergio@hotmail.com
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement