|
![](https://clubstatic.excelhome.net/image/common/ico_lz.png)
楼主 |
发表于 2020-9-13 08:01
|
显示全部楼层
本帖最后由 山中老人 于 2020-9-13 08:43 编辑
下载 19 楼的附件吧!
里面【模块1】 有演示的Sub。照着试试就知道了!
里面的类模块,也有注释!
DevelopDictionary2 在默认情况下就是一个Dictionary,所有Dictionary的使用方法,对DevelopDictionary2都有效!
要使用多列,首先用 DevelopDictionary2.ColumnCount =X '设置列数
========================
Dim dd As DevelopDictionary2
Set dd = New DevelopDictionary2
dd.ColumnCount = 4 '设置列数 (4列)
‘指定列名(可选)。如果未设置列名,就只能使用列号进行列操作。
dd.ColumnName(1) = "ID"
dd.ColumnName(2) = "姓名"
dd.ColumnName(3) = "年龄"
dd.ColumnName(4) = "学历"
’给 1 行(Key=1)的各列赋值
dd.Item(1, "ID") = 11
dd(1, "姓名") = "张三"
dd.Item(1, "年龄") = 25
dd.Item(1, "学历") = "初中"
’输出 1 行(Key=1)的各列的值
Debug.Print dd(1, "ID")
Debug.Print dd.Item(1, "姓名")
Debug.Print dd.Item(1, "年龄")
Debug.Print dd.Item(1, "学历")
’给 2 行(Key=2)的各列赋值
dd.Item(2, "ID") = 12
dd.Item(2, 2) = "李四" ’使用【列号】进行 列操作
dd.Item(2, "年龄") = 54
dd.Item(2, 4) = "文盲"
Call dd.Sort("Key")'按Key值排序(从小到大)
Call dd.Sort("姓名",True)'按[姓名]排序(从大到小)
Debug.Print dd.StringOut(Chr(13), ",")‘以字符串格式输出整个词典内容
|
|