暂时存储一个字典? [英] Temporarily store a Dictionary?
问题描述
同事们热情的同事们!
我的代码填充了一个Dictionary类型变量。稍后,事件处理程序(在选择特定单元格时)需要访问该字典。但是我如何同时存储呢?有没有一种聪明的方法将它写入某个格式的单元格中,然后将其加载到
a字典中?
BW Peter Bunde Hansen
如果您希望能够将Dictionary对象与单元格相关联,则可以创建"父"单元。其条目的单元格地址为键,单元格字典为项目的字典。
例如,在标准模块中:
Public dicParent As Object
Sub CreateParent()
Dim dicCell As Object
'创建父词典
设置dicParent = CreateObject(" ; Scripting.Dictionary")
'为单元格A1创建字典
设置dicCell = CreateObject(" Scripting.Dictionary")
dicCell.Add Key:=" A" ,Item:=" This Item"
dicCell.Add Key:=" B",Item:=" That Item"
'将单元格地址作为键添加到父词典
dicParent.Add键:="
A
1",Item:= dicCell
'为单元格B1创建字典
设置dicCell = CreateObject(" Scripting.Dictionary")
dicCell.Add Key:=" A",Item:= 37
dicCell.Add Key:=" B",Item:= 53
'将其添加到父词典中,单元格地址为键
dicParent.Add Key :="
Fellow passionate colleagues!
My code populates a Dictionary type variable. Later on, an event handler (when selecting a particular cell) needs access to that Dictionary. But how do I store it meanwhile? Is there a clever way to write it into a cell in some formate, then load it back into
a dictionary?
BW Peter Bunde Hansen
If you want to be able to associate Dictionary objects with cells, you could create a "parent" Dictionary whose entries have the cell address as key and the cell dictionary as item.
For example, in a standard module:
Public dicParent As Object Sub CreateParent() Dim dicCell As Object ' Create parent dictionary Set dicParent = CreateObject("Scripting.Dictionary") ' Create dictionary for cell A1 Set dicCell = CreateObject("Scripting.Dictionary") dicCell.Add Key:="A", Item:="This Item" dicCell.Add Key:="B", Item:="That Item" ' Add it to the parent dictionary with cell address as key dicParent.Add Key:="
A
1", Item:=dicCell ' Create dictionary for cell B1 Set dicCell = CreateObject("Scripting.Dictionary") dicCell.Add Key:="A", Item:=37 dicCell.Add Key:="B", Item:=53 ' Add it to the parent dictionary with cell address as key dicParent.Add Key:="
这篇关于暂时存储一个字典?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!