I'm trying to construct a type within a type using Class Modules.
I have a standard code module with my Types, and a Class Module with Set/Let/Get Properties for each type. I then have one as an example of how I'm trying to use them.
This method works with one type, but not with a type within a type. When setting the second type in the standard module, I get a
"Compile error: Method or data member not found".
Class module 1, called clsMod
Option Explicit
Private Memento As clsMo2
Friend Sub SetMemento(NewMemento As clsMo2)
Memento = NewMemento
End Sub
Friend Property Set clsTes2(value As clsMo2)
Memento.m_clsTes2 = value 'This is where it errors, with "m_clsTes2" highlighted
End Property
Friend Property Get clsTes2() As clsMo2
clsTes2 = Memento.m_clsTes2
End Property
Class Module 2, called clsMo2
Option Explicit
Private Memento2 As MyTyp2
Friend Sub SetMemento2(NewMemento As MyTyp2)
Memento2 = NewMemento
End Sub
Public Property Let stri(value As String)
Memento2.stri = value
End Property
Public Property Get stri() As String
stri = Memento2.stri
End Property
Standard code module with Types
Type MyTyp2
stri As String
End Type
Type MyType
m_clsTes2 As MyTyp2
End Type
Standard code module with Sub
Option Explicit
Public clsTest As clsMod
Public clsTes2 As clsMo2
Public Sub Variables()
Set clsTest = New clsMod
Set clsTest.clsTes2 = New clsMo2 'This line triggers the error
clsTest.clsTes2.stri = "TestString" 'This is what I want to get to be able to do
End Sub
m_clsTes2in yourclsMo2classclsTestto have aclsTes2member, theclsModclass would need to expose aPublic Property Get clsTes2() As clsMod2. Protip: drop the Hungarian Notation prefixing scheme, it's really not helping here.Setin the bodies of the methods.Public Property Get clsTes2() as clsMo2, am I doing something else wrong? I shall drop the prefixing, apologies for any damage to your eyes! @TimWilliams thanks. Does having Set clstest..etc in Variables sub not do this?