0
요구 사항 정보를 저장할 클래스를 정의했습니다. 고유 한 req-key를 포함합니다. 내가 객체 저장 키에를 사용하여 objekts을 추가키로 사용자 지정 컬렉션 항목 액세스
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "clsReqCollection"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Option Explicit
Private requirements As Collection
Private Sub Class_Initialize()
Set requirements = New Collection
End Sub
Private Sub Class_Terminate()
Set requirements = Nothing
End Sub
Public Function NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
Set NewEnum = requirements.[_NewEnum]
End Function
Public Sub Add(aRequirement As clsRequirement)
requirements.Add aRequirement, aRequirement.Key
End Sub
Public Sub Remove(cIndex As Variant)
requirements.Remove cIndex
End Sub
Public Property Get Item(cIndex As Variant) As clsRequirement
Attribute Item.VB_UserMemId = 0
Set Item = requirements.Item(cIndex)
End Property
Public Property Get Count() As Integer
Count = requirements.Count
End Property
Public Sub Clear()
Set requirements = New Collection
End Sub
을 다음과 같이
Option Explicit
Private pKey As String
Private pName As String
Private pReqRef As New clsReqCollection
Private pReqType As RequirementType
Private pProblem As String
Public Enum RequirementType
Ziel = 0
Fachanforderung = 1
Produktanforderung = 2
Prozessanforderung = 3
Organisationsanforderung = 4
ITAnforderung = 5
Datenanforderung = 6
RandUndRahmenbedingung = 7
End Enum
''''''''''''''''''''''
' Key property
''''''''''''''''''''''
Public Property Get Key() As String
Key = pKey
End Property
Public Property Let Key(Value As String)
pKey = Value
End Property
''''''''''''''''''''''
' Name property
''''''''''''''''''''''
Public Property Get Name() As String
Name = pName
End Property
Public Property Let Name(Value As String)
pName = Value
End Property
''''''''''''''''''''''
' ReqRef property
''''''''''''''''''''''
Public Property Get ReqRef() As clsReqCollection
ReqRef = pReqRef
End Property
''''''''''''''''''''''
' ReqType property
''''''''''''''''''''''
Public Property Get ReqType() As RequirementType
ReqType = pReqType
End Property
Public Property Let ReqType(Value As RequirementType)
pReqType = Value
End Property
''''''''''''''''''''''
' Problem property
''''''''''''''''''''''
Public Property Get Problem() As String
Problem = pProblem
End Property
Public Property Let Problem(Value As String)
pProblem = Value
End Property
가 지금은 객체 요구 사항을 저장하는 사용자 지정 컬렉션을 구축, 나는 또한 사용자 지정 컬렉션에 액세스 할 수 있도록 희망 키를 제공하여 :
Dim reqs As New clsReqCollection
Dim currReq As clsRequirement
Set currReq = New clsRequirement
currReq.Key = "Key"
currReq.Name = "Name"
reqs.Add currReq
Debug.Print reqs.Item("Key").Name
어떻게 든 마지막 줄이 작동하지 않으면 런타임 오류 '5'가 표시됩니다. 어떤 생각이 여기에 잘못 됐나요? 이처럼