|
楼主 |
发表于 2020-7-14 16:59
|
显示全部楼层
本帖最后由 山中老人 于 2020-7-14 18:10 编辑
测试代码:
Sub cs单列模式()
Dim dd As DevelopDictionary2, dd2 As New DevelopDictionary2, Str As String
Set dd = New DevelopDictionary2
dd("a") = "A"
dd("b") = "B"
dd(3) = "C"
Debug.Print VBA.Join(dd.Keys, ",")
Debug.Print VBA.Join(dd.Items, ",")
Debug.Print dd.RowIndex("b") '行号(从0开始编号)
Debug.Print dd.Index("a") '行号(从0开始编号)
Str = dd.StrJoin(Chr(13)) '全部数据 输出字符串
Debug.Print Str
Call dd2.StrSplit(Str, Chr(13)) '字符串输入
Debug.Print
Debug.Print "dd2"
Debug.Print dd2.StrJoin(Chr(13))
End Sub
Sub cs读写列名()
Dim dd As DevelopDictionary2, dic As Scripting.Dictionary
Set dd = New DevelopDictionary2
dd.ColumnCount = 3 '设置列数
' Debug.Print dd.Dict.Count
dd.ColumnName(0) = "ID"
dd.ColumnName(1) = "姓名"
dd.ColumnName(2) = "年龄"
dd.ColumnName(1) = "年龄2"
Debug.Print dd.ColumnName(0)
Debug.Print dd.ColumnName(1)
Debug.Print dd.ColumnName(2)
Debug.Print dd.ColumnIndex("姓名") '列号
End Sub
Sub cs读写数据() '排序
Dim dd As DevelopDictionary2, dic As Scripting.Dictionary
Set dd = New DevelopDictionary2
dd.ColumnCount = 4 '设置列数
dd.ColumnName(0) = "ID"
dd.ColumnName(1) = "姓名"
dd.ColumnName(2) = "年龄"
dd.ColumnName(3) = "学历"
dd.Item(1, "ID") = 11
dd.Item(1, "姓名") = "张三"
dd.Item(1, "年龄") = 25
dd.Item(1, "学历") = "初中"
' Debug.Print dd.Item(1, "ID")
' Debug.Print dd.Item(1, "姓名")
' Debug.Print dd.Item(1, "年龄")
' Debug.Print dd.Item(1, "学习记录")
dd.Item(2, "ID") = 12
dd.Item(2, 1) = "李四"
dd.Item(2, "年龄") = 54
dd.Item(2, 3) = "文盲"
dd.Item(7, "ID") = 4
dd.Item(7, 1) = "张飞"
dd.Item(7, "年龄") = 15
dd.Item(7, 3) = "幼儿园大班"
Debug.Print dd.StrJoin(Chr(13), ",")
Debug.Print
'按年龄排序
Debug.Print "年龄"
Call dd.Sort(False, , "年龄")
Debug.Print dd.StrJoin(Chr(13), ",")
Debug.Print
'按ID排序
Debug.Print "ID"
Call dd.Sort(False, , "ID")
Debug.Print dd.StrJoin(Chr(13), ",")
Debug.Print
End Sub
Sub cs测试克隆() '复制词典
Dim dd As DevelopDictionary2, dd2 As DevelopDictionary2
Set dd = New DevelopDictionary2
dd.ColumnCount = 4 '设置列数
dd.ColumnName(0) = "ID"
dd.ColumnName(1) = "姓名"
dd.ColumnName(2) = "年龄"
dd.ColumnName(3) = "学历"
dd.Item(1, "ID") = 11
dd.Item(1, "姓名") = "张三"
dd.Item(1, "年龄") = 25
dd.Item(1, "学历") = "初中"
dd.Item(2, "ID") = 12
dd.Item(2, 1) = "李四"
dd.Item(2, "年龄") = 54
dd.Item(2, 3) = "文盲"
dd.Item(7, "ID") = 4
dd.Item(7, 1) = "张飞"
dd.Item(7, "年龄") = 15
dd.Item(7, 3) = "幼儿园大班"
Set dd2 = dd.Clone '克隆
dd2.Item(7, 3) = "大班毕业" '修改指定位置的Item
Debug.Print "dd 列名:" & VBA.Join(dd.ColumnNameS, ",")
Debug.Print dd.StrJoin(Chr(13), ",")
Debug.Print
Debug.Print "dd2 列名:" & VBA.Join(dd2.ColumnNameS, ",")
Debug.Print dd2.StrJoin(Chr(13), ",")
Debug.Print
End Sub |
|