VBA Excel类模块中的子属性 [英] Sub property in VBA Excel class module
问题描述
我有一个名为cTask的模块,其中包含以下代码:
I have a module named cTask with the code below in it:
Private pMile As String
Public Property Get Mile() As String
Mile = pMile
End Property
Public Property Let Mile(Value As String)
pMile = Value
End Property
所以在我的子对象中,我说我是发起人
So in my sub lets say I initiate
dim currtask as cTask
curtask.Mile=TIM
以及
curtask.Mile.stat=2
就像
worksook("qqq").sheets("okko").cells(1,1)...
编辑:
,所以在一个名为cTask的类中进行学习
so Have in one class named cTask
Private pMile As cMile
Public Property Get Mile() As String
Mile = pMile
End Property
Public Property Let Mile(Value As String)
pMile = Value
End Property
并且在类cMile中,我有
and in class cMile I have
Private pstatus As String
Public Property Get status() As String
status = ppstatus
End Property
Public Property Let status(Value As String)
pstatus = Value
End Property
然后在我的子任务中,我要做的就是声明
then in my sub all i do is declare
dim curtask as cTask
这正确吗?它不起作用,所以我一定错过了某些东西
Is this correct? It does not work so I must have missed something
推荐答案
嵌套对象的示例实现
cTask:
Private pMile As cMile
Public Property Get Mile() As cMile
Set Mile = pMile
End Property
Public Property Set Mile(Value As cMile)
Set pMile = Value
End Property
Private Sub Class_Initialize()
Set Me.Mile = New cMile
End Sub
cMile:
cMile:
Private pStatus As String
Private pNumber As Long
Public Property Get Status() As String
Status = pStatus
End Property
Public Property Let Status(Value As String)
pStatus = Value
End Property
Public Property Get Number() As Long
Number = pNumber
End Property
Public Property Let Number(Value As Long)
pNumber = Value
End Property
常规模块:
Regular module:
Sub Tester()
Dim Task As New cTask
Task.Mile.Status = "Done"
Task.Mile.Number = 11
Debug.Print Task.Mile.Status, Task.Mile.Number
End Sub
您原来的问题缺少的是:
What's missing from your original question is this:
curtask.Mile=TIM
目前尚不清楚这是什么意思:它看起来像cMile类上的默认属性,但是VBA并没有真正支持它(或者至少不容易)。
It's not clear what you meant by this: it kind of looks like a "default property" on the cMile class, but that's not really supported in VBA (or at least not easily).
这篇关于VBA Excel类模块中的子属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!