Data = A2.Add(Data) '将第A1列取出的数据2 加至A2列。并取得挤出来的数据 A1.SetData Data '将A2列挤出来的数据加至A1
'看一下A1与A2列的数据顺序 Dim i As Long For i = 0 To A1.Count - 1 MsgBox A1.List(i) '0 1 3 4 5 6 10 '2出来了 ,将A2挤出来的10加至结尾 Next MsgBox "以下开始是A2的数据" For i = 0 To A2.Count - 1 MsgBox A2.List(i) '11 12 13 14 15 16 2 将A1出来的2加入结尾 Next
End Sub '类中的代码 '类名 clsArr Option ExplicitPrivate m_List() As String Private Index As SinglePublic Function LoadData(ParamArray DataList()) ReDim m_List(UBound(DataList)) Dim i As Long For i = 0 To UBound(DataList) m_List(i) = DataList(i) Next Index = 0
End Function Public Property Get List(ByVal cIndex As Single) As String If cIndex >= LBound(m_List) Or cIndex <= UBound(m_List) Then List = m_List((cIndex + Index) Mod (UBound(m_List) + 1)) Else ' ... End If End Property Public Function Add(ByVal Data As String) As String Add = m_List(Index) m_List(Index) = Data
Index = (Index + 1) Mod Count End Function Public Property Get Count() As Single Count = UBound(m_List) + 1 End Property Public Function GetData(ByVal cIndex As Single) As String Dim i As Long
GetData = m_List((cIndex + Index) Mod Count)
For i = 0 To Count - 3 m_List((cIndex + i + Index) Mod Count) = m_List((cIndex + i + Index + 1) Mod Count) Next
m_List((cIndex + Count - 3) Mod Count) = ""
End FunctionPublic Function SetData(ByVal Data As String) As String m_List((Index + Count - 1) Mod Count) = Data End Function
'窗体中的代码
Option ExplicitPrivate Sub Command1_Click()
Dim A1 As New clsArr
A1.LoadData 0, 1, 2, 3, 4, 5 'loadData 是加载数据,每一个类可以看作是一列
MsgBox A1.Count '返回的是这列中数据的总数
MsgBox A1.List(1) '返回这列中第几行的数据,即是第几项。注意下标是从0开始的。即0列为第一个数据。
Dim Data As String
Data = A1.Add("fvf")
'将字符串加至结束处,并得到挤出来的数据放至 Data
Data = A1.GetData(3) '返回 第N项数据,并将此项数据删除,并将此项数据以下的数据全部向上移
Data = A1.SetData("fvf") '将数据加至数组结尾,但不返回数据。 可结合上面的用,上面先删除其中的某一项后,再用这个将数据加至示尾处。
End Sub'以上我给出了此个类的使用方法。'使用示例:Private Sub Command2_Click()
Dim A1 As New clsArr
Dim A2 As New clsArr
'将 A1列的数据 2 移至A2列,并将A2列多出来的数据加至A1列
A1.LoadData 0, 1, 2, 3, 4, 5, 6
A2.LoadData 10, 11, 12, 13, 14, 15, 16
Dim Data As String
Data = A1.GetData(2) '2排在第三位
Data = A2.Add(Data) '将第A1列取出的数据2 加至A2列。并取得挤出来的数据
A1.SetData Data '将A2列挤出来的数据加至A1
'看一下A1与A2列的数据顺序
Dim i As Long
For i = 0 To A1.Count - 1
MsgBox A1.List(i) '0 1 3 4 5 6 10 '2出来了 ,将A2挤出来的10加至结尾
Next
MsgBox "以下开始是A2的数据"
For i = 0 To A2.Count - 1
MsgBox A2.List(i) '11 12 13 14 15 16 2 将A1出来的2加入结尾
Next
End Sub
'类中的代码
'类名 clsArr
Option ExplicitPrivate m_List() As String
Private Index As SinglePublic Function LoadData(ParamArray DataList())
ReDim m_List(UBound(DataList))
Dim i As Long
For i = 0 To UBound(DataList)
m_List(i) = DataList(i)
Next
Index = 0
End Function
Public Property Get List(ByVal cIndex As Single) As String
If cIndex >= LBound(m_List) Or cIndex <= UBound(m_List) Then
List = m_List((cIndex + Index) Mod (UBound(m_List) + 1))
Else
' ...
End If
End Property
Public Function Add(ByVal Data As String) As String
Add = m_List(Index)
m_List(Index) = Data
Index = (Index + 1) Mod Count
End Function
Public Property Get Count() As Single
Count = UBound(m_List) + 1
End Property
Public Function GetData(ByVal cIndex As Single) As String
Dim i As Long
GetData = m_List((cIndex + Index) Mod Count)
For i = 0 To Count - 3
m_List((cIndex + i + Index) Mod Count) = m_List((cIndex + i + Index + 1) Mod Count)
Next
m_List((cIndex + Count - 3) Mod Count) = ""
End FunctionPublic Function SetData(ByVal Data As String) As String
m_List((Index + Count - 1) Mod Count) = Data
End Function