VBA类:Collection.item成员是一个集合。如何检索子集合项元素

VBA Class : Collection.item member is a collection . How to retrieve sub collection item elements

我有此模板数据

文件头((string1,string2 ...)
group1标头(string1,string2 ...)
group1 / line1(字符串1,字符串2 ...)
group1 / line2(字符串1,字符串2 ...)
group2标头(string1,string2 ...)
group2 / line1(字符串1,字符串2 ...)
group2 / line2(string1,string2 ...)

注意:属于组标题和组行的数据即使在同一\\'coloumn \\'上也属于不同类型(原始数据来自文本文件)

我创建了我的主类(填充集合)和数据类(填充项目:cData_Nomination),但是所有事情都可以单独创建,但是我需要创建:

-1文件集合(我有多个文件),用于存储
-栏位(档案标头)和
-x子集合(组)至极存储
---字段(组标题)
--- x子收藏哪个存储
----字段(行数据)

在下面的第170行代码中,.oDpo是组集合,每个数据都存储在具有属性Let(....)的集合上。
一切似乎都存储了!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Public Function NomCreate(m_sFilepath As String, m_objDataList() As String, m_clDpo As Collection) As cData_Nomination

10        On Error GoTo Err_Handler
          Dim Functions As New cFunctions
          Dim objResult As cData_Nomination
          Dim objDate() As String



      'Note : Init Var(s) /Object(s)
      '----------------------------

20        Set objResult = New cData_Nomination

30        With objResult
40            .FileName = Functions.String_NZ(m_sFilepath)
50            .DataSource = Functions.String_NZ(m_objDataList(1))
60            .DelRes = Functions.String_NZ(m_objDataList(2))
70            .DateTime = Functions.Date_NZ(m_objDataList(4) &"" & m_objDataList(5) &":00")
80            objDate = Split(Replace(m_objDataList(6)," -","-"),"-")
90            .DateTimeRange_Start = Functions.Date_NZ(objDate(0))
100           .DateTimeRange_End = Functions.Date_NZ(objDate(1))
110           .Sender = Functions.String_NZ(m_objDataList(7))
120           .Receiver = Functions.String_NZ(m_objDataList(8))
130           .GasPointName = Functions.String_NZ(m_objDataList(9))
140           .GasPointNameExternal = Functions.String_NZ(m_objDataList(10))
150           .Description = Functions.String_NZ(m_objDataList(11))
160           .DataType = Functions.String_NZ(m_objDataList(12))
170           .oDpo = Dpo
180       End With

Err_Exit:
          'Note : Return Function value
190       Set NomCreate = objResult
          'Note : Delete object
200       Set objResult = Nothing
          'Note : Exit
210       Exit Function

Err_Handler:
          'Note : Exit Function
220       GoTo Err_Exit

当我尝试读取数据时遇到问题,我无法通过属性Get访问集合.oDo(请参见以下代码)

1
2
3
4
5
'property belonging to class cData_Nomination
Public Property Let oDpo(ByVal oCollection As Collection)
    Dim m_oDpo As New Collection
    Set m_oDpo = oCollection
End Property

如何将集合传递到现有项目集合(可能是错误的),以及如何从主集合中检索子集合的项目?

我希望这很清楚...

预先感谢


cNum类(父级摘录)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
Private m_sFileName As String
Private oDpo As Collection

Private Sub Class_Initialize()
  Set oDpo = New Collection
End Sub

Public Property Get FileName() As String
    FileName = m_sFileName    
End Property

Public Property Let FileName(ByVal sFileName As String)
    m_sFileName = sFileName    
End Property

Public Property Get Dpo() As Collection
    Set Dpo = oDpo    
End Property

Public Property Set DpoAdd(DpoCollection As Collection)
    Dim DpoItem    
    For Each DpoItem In DpoCollection    
        oDpo.Add DpoItem        
    Next    
End Property

cDop类(父级的子级)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
Private m_sDelivery As String
Private oQty As Collection

Private Sub Class_Initialize()
  Set oQty = New Collection
End Sub

Public Property Get Delivery() As String
    Delivery = m_sDelivery
End Property

Public Property Let Delivery(ByVal sDelivery As String)
    m_sDelivery = sDelivery
End Property


Public Property Get Qty() As Collection
    Set Qty = oQty
End Property

Public Property Set QtyAdd(QtyCollection As Collection)
    Dim QtyItem    
    For Each QtyItem In QtyCollection
        oQty.Add QtyItem
    Next
End Property

cQty类(子级)

1
2
3
4
5
6
7
8
9
Private m_sStatus As String

Public Property Get Status() As String
    Status = m_sStatus
End Property

Public Property Let Status(ByVal sStatus As String)
    m_sStatus = sStatus
End Property

常规模块

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
Sub myModule()

    Dim i As Long
    Dim j As Long
    Dim k As Long
    Dim cNum As cNum
    Dim cDpo As cDpo
    Dim cQty As cQty
    Dim oNum As Collection
    Dim oDpo As Collection
    Dim oQty As Collection

    Set oNum = New Collection
    For i = 1 To 3
        Set cNum = New cNum
        cNum.FileName ="File" & i

        Set oDpo = New Collection
        For j = 1 To 3
            Set cDpo = New cDpo
            cDpo.Qty ="Qty" & i & j
            cDpo.Delivery ="Delivery" & i & j

            Set oQty = New Collection

            For k = 1 To 3
                Set cQty = New cQty
                cQty.Statut ="OK_" & i &"-" & j &"-" & k
                oQty.Add cQty                
            Next k

            Set cDpo.QtyAdd = oQty        

            oDpo.Add cDpo

        Next j

        Set cNum.DpoAdd = oDpo
        oNum.Add cNum

    Next i

    'Set oDpo = Nothing
    '

    For Each cNum In oNum
        Debug.Print""
        Debug.Print"---------FILE ----------------"
        Debug.Print""
        Debug.Print"-[NUM]" & cNum.FileName &" |" & cNum.Info
        Set oDpo = cNum.Dpo
        For Each cDpo In oDpo
            Debug.Print"--[DPO]" & cDpo.Counterpart &" |" & cDpo.Delivery

            Set oQty = cDpo.Qty
            For Each cQty In oQty
                Debug.Print"---[QTY]" & cQty.Quantity &" |" & cQty.Statut
            Next
        Next

    Next

End Sub