我很困惑。我是VBA课程的新手。我想将多个方法添加到类的属性,或将属性添加到另一个属性。我的术语可能不正确吗?
我可以添加一个属性,但是我想更深入地研究。
例如,如果我要成为一个班级人员:
PersonClass.Features.Hair.Texture.Color
PersonClass.Features.Hair.Texture.Style
PersonClass.Features.Hair.Length
我不确定该怎么做。
例如
MyClass.MyProperty.MyMethod1
MyClass.MyProperty.MyMethod2
MyClass.MyProperty.MyMethod3
或
MyClass.MyProperty.MyMethod1.MyMethod2
答案 0 :(得分:2)
下面是一个示例,用于说明注释中提到的概念:
主表单
Option Explicit
Private Sub Form_Load()
Dim p As Person
Set p = New Person
p.Features.Hair = "Red"
MsgBox p.Features.Hair
End Sub
人员班
Option Explicit
Private m_Features As Features
Private Sub Class_Initialize()
Set m_Features = New Features
End Sub
Public Property Get Features() As Features
Set Features = m_Features
End Property
功能类
Option Explicit
Private m_Hair As String 'this would actually be another class
'in your example
Public Property Get Hair() As String
Hair = m_Hair
End Property
Public Property Let Hair(ByVal Value As String)
m_Hair = Value
End Property