Dictionary —- 字典对象
说明:一个能够增删改的容器,同时也是一个COM组件
添加项
Set dic=CreateObject(“Scripting.Dictionary”)
dic.Add “a”,”test was a”
dic.Add “b”,”test was b”
dic.Add “c”,”test was c”
MsgBox dic.Item(“a”) ’item可省略
删除项
Set dic=CreateObject(“Scripting.Dictionary”)
dic.Add “a”,”test was a”
dic.Add “b”,”test was b”
dic.Add “c”,”test was c”
MsgBox dic.Count ’3个
dic.Remove(“a”)
MsgBox dic.Count ’2个
Msgbox dic(“a”) ’已空修改项 Set dic=CreateObject(“Scripting.Dictionary”)
dic.Add “a”,”test was a”
dic.Add “b”,”test was b”
dic.Add “c”,”test was c”
MsgBox dic(“a”) ’修改之前
dic.Item(“a”)=”zzxxbb112″
MsgBox dic(“a”) ’修改之后
本文介绍了如何使用VBA中的字典对象进行增删改操作,包括添加项、删除项和修改项的具体实现方法。

被折叠的 条评论
为什么被折叠?



