我有一个名为 cTask 的模块,其中包含以下代码:
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
Run Code Online (Sandbox Code Playgroud)
所以在我的 sub 中可以说我发起
dim currtask as cTask
Run Code Online (Sandbox Code Playgroud)
我想写
curtask.Mile=TIM
Run Code Online (Sandbox Code Playgroud)
并且
curtask.Mile.stat=2
Run Code Online (Sandbox Code Playgroud)
就像
worksook("qqq").sheets("okko").cells(1,1)...
Run Code Online (Sandbox Code Playgroud)
我如何在我的班级中做嵌套的属性?
编辑:所以在一个名为 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
Run Code Online (Sandbox Code Playgroud)
在课堂上,我有
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
Run Code Online (Sandbox Code Playgroud)
然后在我的潜艇中我所做的就是声明
dim curtask as cTask
Run Code Online (Sandbox Code Playgroud)
这样对吗?它不起作用所以我一定错过了什么
嵌套对象的示例实现
任务:
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
Run Code Online (Sandbox Code Playgroud)
英里:
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
Run Code Online (Sandbox Code Playgroud)
常规模块:
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
Run Code Online (Sandbox Code Playgroud)
您的原始问题中缺少的是:
curtask.Mile=TIM
Run Code Online (Sandbox Code Playgroud)
不清楚您的意思:它看起来像是 cMile 类上的“默认属性”,但 VBA 并不真正支持它(或者至少不容易)。