@VBA
Dictionary常用方法
如何插入一段漂亮的代码片
代码片
.
Sub test()
Dim t1 as Object
''定义类型
Set t1 = CreateObject("Scripting.Dictionary")
''字典增加数据不允许重复key
t1.Add 1, "A": t1.Add 2, "B": t1.Add 3, "C": t1.Add 4, "D"
''字典增加数据允许重复key 有则覆盖,无的添加
t1(1)="AA":t1(2)="BB":t1(12)="EE":
''判断是否存在的key
t1.exists(1)
''字典删除数据
if t1.exists(1) then t1.Remove 1
''循环字典
k = t1.keys: v = t1.items
For i = 0 To t1.Count - 1
Debug.Print k(i) & " " & v(i)
Next i
''清空
t1.RemoveALl
End Sub