2015-05-29 56 views
0

我有這樣的模板數據VBA類:Collection.item成員是一個集合。如何檢索子集item元素

頭文件((字符串1,字符串...) 1組頭(字符串1,字符串...) 組1 /線路1(字符串1,字符串。 ...) group1/line2(string1,string2 ...) group2 header(string1,string2 ...) group2/line1(string1,string2 ...) group2/line2(string1,string2 ...)

注意:即使屬於同一個「coloumn」(原始數據來自文本文件),屬於組標題和組行的數據也是不同的類型

創建我的主類(填充集合)和數據類(填充項目:cData_Nomination),一切正常individualy但我需要創建:

-1文件集(我有數倍的文件),它存儲 - 字段(文件頭)和 - ×副集合(組)至極商店 ---字段(組報頭) ---×副收集它們存儲 ----字段(行數據)

在在線170.oDpo上的以下代碼是組集合,每個數據都存儲在具有屬性Let(....)的集合上。 一切似乎都是商店!

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 

當我嘗試讀取數據我有一個問題,我無法訪問通過屬性獲取集合.oDo(參見下面的代碼)

'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 

如何傳遞收集到的現有的項目集合(我可能錯了)以及如何從主集合中檢索我的子集合項目?

我希望這是明確的......

在此先感謝

回答

0

類CNUM(母公司提取物)

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(父母的兒童)

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 

Class cQty(S UB兒童)

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 

普通模塊

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 
相關問題