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

时间:2015-05-29 14:58:44

标签: vba class collections

我有这个模板数据

文件头((string1,string2 ...) group1标头(string1,string2 ......) group1 / line1(string1,string2 ...) group1 / line2(string1,string2 ...) group2标头(string1,string2 ......) group2 / line1(string1,string2 ...) group2 / line2(string1,string2 ...)

注意:属于组标题和组行的数据是不同的类型,即使它们位于相同的“coloumn”(原始数据来自文本文件)

我创建了我的主类(填充集合)和数据类(填充项目:cData_Nomination),一切都是单独工作但我需要创建:

-1文件集合(我有多个文件)存储 - 字段(文件头)和 - 存储的x子集合(组) ---字段(组头) --- x子集合哪个商店 ----字段(行数据)

在第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

如何将集合传递给现有的项目集合(我可能错了)以及如何从主集合中检索我的子集合项目?

我希望它很清楚......

提前致谢

1 个答案:

答案 0 :(得分:0)

班级cNum(父母提取)

WebSocket.h

班级cDop(家长的孩子)

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

班级cQty(子孩子)

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

常规模块

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