📄 mytable.cls
字号:
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
Persistable = 0 'NotPersistable
DataBindingBehavior = 0 'vbNone
DataSourceBehavior = 0 'vbNone
MTSTransactionMode = 0 'NotAnMTSObject
END
Attribute VB_Name = "MDD_Table"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'本模块表示一个表格。
Private TemRows() As MDD_Row '记录集。
Public Name As String '表格名称.
Private TemFields As MDD_Row '一条记录的结构。
Private TemRowCount As Long '记录数量。
Public Property Get RowCount() As Long '只读属性.
RowCount = TemRowCount
End Property
Public Sub ClearRows()
TemRowCount = 0
ReDim Preserve TemRows(TemRowCount)
End Sub
Private Sub Class_Initialize()
'初始化该对象.
Name = ""
TemRowCount = 0
ReDim Preserve TemRows(TemRowCount)
Set TemFields = New MDD_Row
End Sub
Public Property Get Fields() As MDD_Row '只读属性.
Set Fields = TemFields
End Property
Public Property Get Rows(ByVal RowIndex As Long) As MDD_Row
'获取记录(可进一步对其操作).
If RowIndex >= 0 And RowIndex < TemRowCount Then
Set Rows = TemRows(RowIndex)
End If
End Property
Public Sub AddRow(Optional ByVal InRow As MDD_Row)
'添加记录数据.
Dim ForIndex As Long
TemRowCount = TemRowCount + 1
ReDim Preserve TemRows(TemRowCount)
Set TemRows(TemRowCount - 1) = New MDD_Row
For ForIndex = 0 To Fields.FieldCount - 1 Step 1 '复制记录结构及值(默认值)。
TemRows(TemRowCount - 1).AddField TemFields.Items(ForIndex).Name, TemFields.Items(ForIndex).DataType
Next
If InRow Is Nothing Then Exit Sub
If Me.Fields.FieldCount <> InRow.FieldCount Then
MsgBox "添加的记录数据结构与表格字段结构不一致!" & Chr(13) & "只添加了一条记录,数据被放弃!", vbOKOnly, "结构错..."
Exit Sub
End If
For ForIndex = 0 To Me.Fields.FieldCount - 1
If Me.Fields.Items(ForIndex).DataType <> InRow.Items(ForIndex).DataType Then
MsgBox "添加的记录数据结构与表格字段结构不一致!" & Chr(13) & "只添加了一条记录,数据被放弃!", vbOKOnly, "结构错..."
Exit Sub
End If
Next
For ForIndex = 0 To Me.Fields.FieldCount - 1
TemRows(TemRowCount - 1).Items(ForIndex).Value = InRow.Items(ForIndex).Value
Next
End Sub
Public Sub DelRow(ByVal RowIndex As Long)
'删除记录.
Dim ForIndex As Long
If RowIndex < 0 Or RowIndex >= TemRowCount Then Exit Sub
For ForIndex = RowIndex To TemRowCount - 2 Step 1
Set TemRows(ForIndex) = TemRows(ForIndex + 1)
Next
TemRowCount = TemRowCount - 1
ReDim Preserve TemRows(TemRowCount)
End Sub
Public Function IndexUpdate(ByVal FieldIndex As Long) As Boolean
'按指定的字段进行排顺.
Dim RowIndexX As Long
Dim RowIndexY As Long
Dim TemRow As MDD_Row
IndexUpdate = True
If FieldIndex < 0 Or FieldIndex >= Me.Fields.FieldCount Then Exit Function
For RowIndexX = 0 To Me.RowCount - 1
For RowIndexY = 0 To Me.RowCount - 2
If TemRows(RowIndexY).Items(FieldIndex).Value > TemRows(RowIndexY + 1).Items(FieldIndex).Value Then
Set TemRow = TemRows(RowIndexY)
Set TemRows(RowIndexY) = TemRows(RowIndexY + 1)
Set TemRows(RowIndexY + 1) = TemRow
End If
Next
Next
IndexUpdate = False
End Function
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -