3

我有一个集合如下:

Set NodeColl = New Collection
NodeColl.Add "Node 1", "Node 1"
NodeColl.Add "Node 2", "Node 2"
NodeColl.Add "Node 3", "Node 3"

我想知道是否有一种简单的方法可以重命名选择性项目的键而不影响其他项目或集合本身。例如,像 NodeColl.Items("Node 1").Key = "Some string"

4

1 回答 1

7

不,您需要手动添加和删除;

with NodeColl
    .add .Item("Node 2"), "New Key", , "Node 2"
    .remove "Node 2"
end with

或者通过添加对Microsoft Scripting Runtime的引用或使用Dictionary允许这样做的 a ;

dim NodeColl as object: Set NodeColl = createobject("Scripting.dictionary")
NodeColl.add "key for Node 1", "Node 1"
NodeColl.add "key for Node 2", "Node 2"
NodeColl.add "key for Node 3", "Node 3"

'//direct rename allowed;
NodeColl.Key("key for Node 2") = "New Key here"
于 2012-05-23T15:00:00.867 回答