今日学习目标
- 理解Dictionary对象
- 掌握字典的增删改查
- 学会使用字典处理数据
知识点
Dictionary对象
vbaDim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
dict.Add "key", value
dict("key") = newValue
dict.Exists("key")
dict.Remove("key")今日代码
vbaDim dict As Object
Set dict = CreateObject("Scripting.Dictionary")
dict.Add "key", value
dict("key") = newValue
dict.Exists("key")
dict.Remove("key")练习题
- 使用字典进行数据查询
- 统计词频
- 实现数据映射
参考解答
1. 创建字典后用dict.Add "key", value添加数据,用dict("key")或dict.Item("key")查询值。 2. 遍历文本,用Exists检查词是否已存在,存在则+1计数,不存在则添加并设为1。 3. 建立两个字段的映射关系,如员工编号→姓名、部门代码→部门名称等字典查询表。
由在线工具箱(www.vba.net)整理制作