⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 cdataitems.cls

📁 Data monkey是一个强大的是数据传输和转换应用程序。使用DataMonkey用户可以把复杂的文本文件格式
💻 CLS
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
END
Attribute VB_Name = "CDataItems"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
Attribute VB_Ext_KEY = "SavedWithClassBuilder" ,"Yes"
Attribute VB_Ext_KEY = "Collection" ,"CDataPoint"
Attribute VB_Ext_KEY = "Member0" ,"CDataPoint"
Attribute VB_Ext_KEY = "Top_Level" ,"Yes"
'local variable to hold collection
Private mCol As Collection

Public Function InsertDataItemObject(newObj As CDataItem, insertAt As Integer) As CCheckPoint
    On Error GoTo eHandler
    Dim i As Integer
    Set InsertDataItemObject = Nothing
    
    If newObj Is Nothing Then Exit Function
    
    newObj.index = insertAt

    If insertAt > mCol.Count Then
        ' Insert as last item.
        newObj.index = insertAt
        mCol.Add newObj, newObj.GetID
    Else
        ' Insert the item into our collection before the item that
        ' currently occupies the position indicated.
        mCol.Add newObj, newObj.GetID, mCol(insertAt).GetID
        
        For i = mCol.Count To insertAt + 1 Step -1
            mCol(i).index = i
        Next i
    End If
    
    Set InsertDataItemObject = newObj
    Exit Function
eHandler:

End Function

Public Function Copy() As CDataItems
    On Error GoTo eHandler
    Set Copy = Nothing

    Dim newObj As CDataItems
    Set newObj = New CDataItems
    Dim obj As CDataItem
    
    For Each obj In mCol
        newObj.Add obj.Copy
    Next obj
    Set Copy = newObj
    Set newObj = Nothing
    Exit Function

eHandler:
    LogError "CDataItems", "Copy", Error(Err), False

End Function

' Reorder the items in our collection by index.
Public Sub Reorder()

    Dim temp As Collection
    Dim i As Integer
    
    Set temp = mCol
    Set mCol = Nothing
    Set mCol = New Collection
    
    i = 0
    Do While temp.Count > 0
        Dim obj As Object
        Dim j As Integer
        Dim smallest As Integer
            
        i = i + 1       'Incremement the new index.
        
        '***************************************
        ' Find the object with the lowest index.
        '***************************************
        
        smallest = 1
        For j = 1 To temp.Count
            If temp(j).index < temp(smallest).index Then
                smallest = j
            End If
        Next j
        
        Set obj = temp(smallest)
        obj.index = i
        mCol.Add item:=obj, key:=obj.GetID
        temp.Remove obj.GetID
        Set obj = Nothing
    Loop

End Sub

Public Function ItemByName(name As String) As CDataItem
    On Error GoTo eHandler
    Set ItemByName = Nothing
    
    Dim di As CDataItem
    
    For Each di In mCol
        If di.name = name Then
            Set ItemByName = di
            Set di = Nothing
            Exit Function
        End If
    Next di
    Exit Function
    
eHandler:
    LogError "CDataItems", "ItemByName", Error(Err)
End Function
Public Function Add(Optional newItem As CDataItem = Nothing, Optional AutoIndex As Boolean = True) As CDataItem

    On Error GoTo eHandler

    'create a new object
    Dim objNewMember As CDataItem
    
    If newItem Is Nothing Then
        Set objNewMember = New CDataItem
    Else
        Set objNewMember = newItem
    End If
    
    ' Automatically calculate the index value to place the
    ' new member at the end of our list of checkpoints.
    If AutoIndex Then
        Dim highest As Integer
        Dim item As CDataItem
        highest = 0

        ' Find the current highest index.
        For Each item In mCol
            If item.index > highest Then
                highest = item.index
            End If
        Next
        
        ' Add the new index.
        objNewMember.index = highest + 1
    End If
    
    'set the properties passed into the method
    mCol.Add objNewMember, objNewMember.GetID

    'return the object created
    Set Add = objNewMember
    Set objNewMember = Nothing
    Exit Function
    
eHandler:
    MsgBox Error(Err)

End Function

Public Property Get item(vntIndexKey As Variant) As CDataItem
Attribute item.VB_UserMemId = 0
    On Error Resume Next
    
    Set item = Nothing
    
    'used when referencing an element in the collection
    'vntIndexKey contains either the Index or Key to the collection,
    'this is why it is declared as a Variant
    'Syntax: Set foo = x.Item(xyz) or Set foo = x.Item(5)
    
    Set item = mCol(vntIndexKey)
    
End Property



Public Property Get Count() As Long
    'used when retrieving the number of elements in the
    'collection. Syntax: Debug.Print x.Count
    Count = mCol.Count
End Property


Public Sub Remove(vntIndexKey As Variant)
    'used when removing an element from the collection
    'vntIndexKey contains either the Index or Key, which is why
    'it is declared as a Variant
    'Syntax: x.Remove(xyz)


    mCol.Remove vntIndexKey
End Sub


Public Property Get NewEnum() As IUnknown
Attribute NewEnum.VB_UserMemId = -4
Attribute NewEnum.VB_MemberFlags = "40"
    'this property allows you to enumerate
    'this collection with the For...Each syntax
    Set NewEnum = mCol.[_NewEnum]
End Property


Private Sub Class_Initialize()
    'creates the collection when this class is created
    Set mCol = New Collection
End Sub


Private Sub Class_Terminate()
    'destroys collection when this class is terminated
    Set mCol = Nothing
End Sub

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -