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

📄 rangedarraylist.cls

📁 这是一个在vb下实现的各种加密程序,可以实现一般的文本加密和文件加密,但是很多算法都是已经被人破解过的.
💻 CLS
📖 第 1 页 / 共 2 页
字号:
VERSION 1.0 CLASS
BEGIN
  MultiUse = -1  'True
  Persistable = 0  'NotPersistable
  DataBindingBehavior = 0  'vbNone
  DataSourceBehavior  = 0  'vbNone
  MTSTransactionMode  = 0  'NotAnMTSObject
END
Attribute VB_Name = "RangedArrayList"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'    CopyRight (c) 2004 Kelly Ethridge
'
'    This file is part of VBCorLib.
'
'    VBCorLib is free software; you can redistribute it and/or modify
'    it under the terms of the GNU Library General Public License as published by
'    the Free Software Foundation; either version 2.1 of the License, or
'    (at your option) any later version.
'
'    VBCorLib is distributed in the hope that it will be useful,
'    but WITHOUT ANY WARRANTY; without even the implied warranty of
'    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
'    GNU Library General Public License for more details.
'
'    You should have received a copy of the GNU Library General Public License
'    along with Foobar; if not, write to the Free Software
'    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
'
'    Module: RangedArrayList
'

''
' This class is used to represent a sub-array view of the parent ArrayList object.
'

Option Explicit
Implements IObject
Implements ArrayList
Implements ICollection
Implements IEnumerable
Implements ICloneable
Implements IList

Private mList       As ArrayList
Private mVersion    As Long
Private mIndex      As Long
Private mCount      As Long



'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   Friend Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Friend Sub Init(ByVal List As ArrayList, ByVal Index As Long, ByVal Count As Long)
    Set mList = List
    mVersion = List.Version
    mIndex = Index
    mCount = Count
End Sub


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   Private Helpers
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Sub VerifyVersion()
    If mVersion <> mList.Version Then _
        Throw Cor.NewInvalidOperationException("The base ArrayList has been modified outside of the Ranged list.")
End Sub

Private Function GetCollectionSize(ByRef c As Variant) As Long
    If IsArray(c) Then
        If cArray.IsNull(c) Then _
            Throw Cor.NewArgumentNullException(Environment.GetResourceString(ArgumentNull_Array), "c")
        
        GetCollectionSize = UBound(c) - LBound(c) + 1
    
    ElseIf IsObject(c) Then
        If c Is Nothing Then _
            Throw Cor.NewArgumentNullException(Environment.GetResourceString(ArgumentNull_Collection), "c")
        
        If TypeOf c Is Collection Then
            Dim Col As Collection
            Set Col = c
            GetCollectionSize = Col.Count
        ElseIf TypeOf c Is ICollection Then
            Dim ICol As ICollection
            Set ICol = c
            GetCollectionSize = ICol.Count
        Else
            Throw Cor.NewInvalidCastException("An ICollection or VBA.Collection object is required.")
        End If
    Else
        Throw Cor.NewInvalidCastException("An ICollection object, VBA.Collection or an Array is required.")
    End If
End Function


'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
'   ArrayList Interface
'''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
Private Function ArrayList_Add(Value As Variant) As Long
    Call VerifyVersion
    Call mList.Insert(mIndex + mCount, Value)
    ArrayList_Add = mCount
    mCount = mCount + 1
    mVersion = mVersion + 1
End Function

Private Sub ArrayList_AddRange(c As Variant)
    Call VerifyVersion
    Call mList.InsertRange(mIndex + mCount, c)
    mCount = mCount + GetCollectionSize(c)
    mVersion = mVersion + 1
End Sub

Private Function ArrayList_BinarySearch(Value As Variant, Optional ByRef Index As Variant, Optional ByRef Count As Variant, Optional ByVal Comparer As IComparer) As Long
    Call VerifyVersion
    
    Dim ElemCount   As Long
    Dim ElemIndex   As Long
    Dim Result      As Long
    Result = GetOptionalListRange(mCount, Index, ElemIndex, Count, ElemCount)
    If Result <> NO_ERROR Then Call ThrowListRangeException(Result, ElemIndex, "Index", ElemCount, "Count", IsMissing(Index))
    
    Dim i As Long
    i = mList.BinarySearch(Value, mIndex + ElemIndex, ElemCount, Comparer)
    If i >= 0 Then i = i - mIndex
    ArrayList_BinarySearch = i
End Function

Private Property Let ArrayList_Capacity(ByVal RHS As Long)
    Call VerifyVersion
    mList.Capacity = RHS
    mVersion = mVersion + 1
End Property

Private Property Get ArrayList_Capacity() As Long
    Call VerifyVersion
    ArrayList_Capacity = mList.Capacity
End Property

Private Sub ArrayList_Clear()
    Call VerifyVersion
    If mCount = 0 Then Exit Sub
    Call mList.RemoveRange(mIndex, mCount)
    mCount = 0
    mVersion = mVersion + 1
End Sub

Private Function ArrayList_Clone() As ArrayList
    Call VerifyVersion
    Dim Ret As New RangedArrayList
    Call Ret.Init(mList.Clone, mIndex, mCount)
    Set ArrayList_Clone = Ret
End Function

Private Function ArrayList_Contains(Value As Variant, Optional ByVal Comparer As IComparer) As Boolean
    Call VerifyVersion
    ArrayList_Contains = (mList.IndexOf(Value, mIndex, mCount, Comparer) >= 0)
End Function

Private Sub ArrayList_CopyTo(DstArray As Variant, Optional ArrayIndex As Variant)
    Call VerifyVersion
    
    Dim Index As Long
    If IsMissing(ArrayIndex) Then Index = LBound(DstArray) Else Index = ArrayIndex
    Call mList.CopyToEx(mIndex, DstArray, Index, mCount)
End Sub

Private Sub ArrayList_CopyToEx(ByVal Index As Long, DstArray As Variant, ByVal ArrayIndex As Long, ByVal Count As Long)
    Call VerifyVersion
    
    Dim Result As Long
    Result = VerifyListRange(mCount, Index, Count)
    If Result <> NO_ERROR Then Call ThrowListRangeException(Result, Index, "Index", Count, "Count")
    
    Call mList.CopyToEx(mIndex + Index, DstArray, ArrayIndex, Count)
End Sub

Private Property Get ArrayList_Count() As Long
    Call VerifyVersion
    ArrayList_Count = mCount
End Property

Private Function ArrayList_Equals(Value As Variant) As Boolean
    ArrayList_Equals = IObject_Equals(Value)
End Function

Private Function ArrayList_GetEnumerator(Optional ByRef StartIndex As Variant, Optional ByRef Count As Variant) As Object
    Call VerifyVersion
    
    Dim ElemCount   As Long
    Dim ElemIndex   As Long
    Dim Result      As Long
    Result = GetOptionalListRange(mCount, StartIndex, ElemIndex, Count, ElemCount)
    If Result <> NO_ERROR Then Call ThrowListRangeException(Result, ElemIndex, "StartIndex", ElemCount, "Count", IsMissing(StartIndex))
    
    
    Dim Ret As New ArrayListEnumerator
    Call Ret.Init(Me, ElemIndex, ElemCount)
    Set ArrayList_GetEnumerator = Ret
End Function

Private Function ArrayList_GetHashCode() As Long
    ArrayList_GetHashCode = IObject_GetHashcode
End Function

Private Function ArrayList_GetRange(ByVal Index As Long, ByVal Count As Long) As ArrayList
    Dim Result As Long
    Result = VerifyListRange(mCount, Index, Count)
    If Result <> NO_ERROR Then Call ThrowListRangeException(Result, Index, "Index", Count, "Count")
    
    Dim Ret As RangedArrayList
    Set Ret = New RangedArrayList
    Call Ret.Init(Me, Index, Count)
    Set ArrayList_GetRange = Ret
End Function

Private Function ArrayList_IndexOf(Value As Variant, Optional ByRef StartIndex As Variant, Optional ByRef Count As Variant, Optional ByVal Comparer As IComparer) As Long
    Call VerifyVersion
    
    Dim ElemCount   As Long
    Dim ElemIndex   As Long
    Dim Result      As Long
    Result = GetOptionalListRange(mCount, StartIndex, ElemIndex, Count, ElemCount)
    If Result <> NO_ERROR Then Call ThrowListRangeException(Result, ElemIndex, "StartIndex", ElemCount, "Count", IsMissing(StartIndex))
    
    Dim Index As Long
    Index = mList.IndexOf(Value, mIndex + ElemIndex, ElemCount, Comparer)
    If Index >= 0 Then Index = Index - mIndex
    ArrayList_IndexOf = Index
End Function

Private Sub ArrayList_Insert(ByVal Index As Long, Value As Variant)
    Call VerifyVersion
    
    If Index < 0 Or Index > mCount Then _
        Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_Index), "index", Index)
    
    Call mList.Insert(mIndex + Index, Value)
    mCount = mCount + 1
    mVersion = mVersion + 1
End Sub

Private Sub ArrayList_InsertRange(ByVal Index As Long, c As Variant)
    Call VerifyVersion
    
    If Index < 0 Or Index > mCount Then _
        Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_Index), "index", Index)
    
    Dim TotalElements As Long
    TotalElements = GetCollectionSize(c)
    Call mList.InsertRange(mIndex + Index, c)
    mCount = mCount + TotalElements
    mVersion = mVersion + 1
End Sub

Private Property Get ArrayList_IsFixedSize() As Boolean
    ArrayList_IsFixedSize = mList.IsFixedSize
End Property

Private Property Get ArrayList_IsReadOnly() As Boolean
    ArrayList_IsReadOnly = mList.IsReadOnly
End Property

Private Property Set ArrayList_Item(ByVal Index As Long, RHS As Variant)
    Call VerifyVersion
    If Index < 0 Or Index >= mCount Then _
        Throw Cor.NewArgumentOutOfRangeException(Environment.GetResourceString(ArgumentOutOfRange_Index), "index", Index)

⌨️ 快捷键说明

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