컬렉션에 키를 추가 할 때 이상한 문제가 있습니다. 런타임 오류 13 : 형식 불일치VBA에서 컬렉션에 키 추가
모듈 코드 :
'comment
Option Explicit
'comment
Sub testChildren()
'This is in Normal module
Dim mRoot As cMyClass, mc As cMyClass
Set mRoot = New cMyClass
With mRoot
'add collections
.Init 100, "john"
Set mc = New cMyClass
' Here I add the key that gives the run-time error 13
.Children.Add mc.Init(200, "janet"), mc.Key
Set mc = New cMyClass
' This one also generates run-time error 13 in case the previous adding is disabled
.Children.Add mc.Init(201, "john"), mc.Key
' Generate output
MsgBox (.Name & " has " & CStr(.Children.Count) & " children named " & _
.Children(1).Name & " and " & .Children(2).Name)
End With
End Sub
클래스 모듈 CmyClass에서 은 '이
Option Explicit
Private pKey As Long
Private pName As String
Private pChildren As Collection
'Define Properties
Public Property Get Key() As Long
Key = pKey
End Property
'comment
Public Property Get Name() As String
Name = pName
End Property
'comment
Public Property Get Children() As Collection
Set Children = pChildren
End Property
'comment
Public Property Let Key(p As Long)
pKey = p
End Property
' Define Methods
Public Function Init(k As Long, sName As String) As cMyClass
pKey = k
pName = sName
Set pChildren = New Collection
Set Init = Me
End Function
'comment
'comment
'mc.Key'를'Cstr (mc.Key) '로 바꾸십시오. –
고마워요. – Richie10