How to have a class have a UDT as property?
I want a class to have a property taht returns and takes a UDT.
But it won't work.
My code:
VB Code:
'Module:
Public Type tA
B As Long
End Type
'Class:
Private vA As tA
Public Property Get A() As tA
A = vA
End Property
Public Property Let A(val As tA)
vA = val
End Property
'Form:
Private C As Class1
Private Sub Form_Load()
Set C = New Class1
C.A.B = 1
End Sub
This gives a compiler error:
Quote:
Only public user defined types defined in public object modules can be used as parameters or return types for public procedures of class modules or as fields of public user defined types
What am I doing wrong?
How do I make a public object module?
Re: How to have a class have a UDT as property?
VB Code:
[B]Friend [/B]Property Get A() As tA
A = vA
End Property
[B]Friend [/B]Property Let A(val As tA)
vA = val
End Property
Re: How to have a class have a UDT as property?
Thanks.
This won't let me put a value in C.A.B (part of the UDT) directly though.
But I can first fill a temporary variable and then assign that to C.A (the entire UDT).
The IDE will let me enter C.A.B = 2 but that starts the Get instead of the Let property.
Is that how it works?
Re: How to have a class have a UDT as property?
yes you'll have to pass whole UDTs with that Get/Let - you can also write a separate properties for each UDT member if you so wish.