当我向VBA集合中添加一些值后,有什么方法可以保留所有键的列表吗?
例如
Dim coll as new Collection
Dim str1, str2, str3
str1="first string"
str2="second string"
str3="third string"
coll.add str1, "first key"
coll.add str2, "second key"
coll.add str3, "third key"
我知道如何保留字符串列表:
first string
second string
third string
再说一遍:有什么办法可以保留 key 吗?
first key
second key
third key
注意:我通过 AutoCAD 2007 使用 VBA
最佳答案
如果您打算使用默认的 VB6 Collection
,那么最简单的方法是:
col1.add array("first key", "first string"), "first key"
col1.add array("second key", "second string"), "second key"
col1.add array("third key", "third string"), "third key"
然后您可以列出所有值:
Dim i As Variant
For Each i In col1
Debug.Print i(1)
Next
或所有键:
Dim i As Variant
For Each i In col1
Debug.Print i(0)
Next
关于VBA集合: list of keys,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5702362/