내가 정확히 내가 원하는 것 같다 SO에 큰 게시물을 발견 : Is it possible to access a parent property from a child that is in a collection? 그러나 내 적응이 나에게주고있다 Object doesn't support this property or method.
VBA 패스 부모 클래스가
내 코드와 Tomalak :
부모 클래스 - clsComputer
Option Explicit
Private pCD As clsCD
''''''''''''''''''''''''''''''
' CD property
''''''''''''''''''''''''''''''
Public Property Get CD() As clsCD
If pCD Is Nothing Then
Set pCD = New clsCD
'Per Mat's Mug post, drop the parenthesis
pCD.Initialze Me
End If
Set CD = pCD
End Property
Public Property Set CD(value As clsCD)
pCD = value
End Property
하위 클래스 - clsCD
이Option Explicit
Private pParent As clsComputer
'''''''''''''''''''''''''''''
' Status property - READ ONLY
'''''''''''''''''''''''''''''
Public Property Get Status(Optional strHost As String) As String
Dim strResult As String
If strHost = "" Then strHost = Me.Parent.HostName
strResult = RunCMD("cmd /c ""winrs -r:" & strHost & _
" reg query hklm\system\currentcontrolset\services\cdrom /v start""")
If InStr(1, strResult, "0x4", vbTextCompare) Then
Status = "Disabled"
Else
Status = "Enabled"
End If
End Property
'''''''''''''''''''''''''
' Parent property
'''''''''''''''''''''''''
Public Property Get Parent() As clsComputer
Set Parent = pParent
End Property
'Because as Tomalak points out, you use Set with Objects.
Public Property Set Parent(Obj As clsComputer)
Set pParent = Obj
End Property
'''''''''''''''''''''''''
' Initialize Method
'''''''''''''''''''''''''
Public Sub Initialize(Obj As clsComputer)
Set Me.Parent = Obj
End Sub
코드 모듈 - 나는 나를 테스트하는 경우 Module1의
Sub test()
Dim oPC As clsComputer
Set oPC = New clsComputer
Debug.Print "CD Status: " & oPC.CD.Status
End Sub
, 그것은 객체입니다 (예를 들면, If IsObject(Me) Then Stop
사실 평가) 및 IntelliSense를 모두 보여줍니다 내가 입력했을 때 clsComputer의 속성 및 메서드 Me.
지역 창에 Me가 clsComputer 개체로 표시됩니다. 확인을 위해 알아두면 모든 것이 clsComputer 객체라는 것을 알기 때문에 내가 뭘 잘못하고있는 걸까요?
아하! 이것과 @tomalak 사이에, 그것을 수정합니다!나는 나의 포스트를 새롭게 할 것이다. – Tim
굉장합니다. 마침내 저는 팸알을 원한다는 마지막 비트를 알고 있습니다. 감사. – Tomalak