VBA集合: list of keys

标签 vba collections

当我向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/

相关文章:

ios - Swift:将 oldArray[][] 复制到 newArray[][] 会导致错误(类型 'Any' 没有下标成员)

vba - 使用 .resize() 后将文本存储在变体中

regex - 如何捕获两个字母?

excel - VBA 生成 -35 到 +5 之间的随机数

excel - 条件格式的循环和偏移

java - 基于实例变量java对列表进行排序

excel - 在 VBA 中使用 IF

java - 返回 Hashset 中具有最高值的类对象

java - HashSet 在构造函数中调用可重写的方法

c# - 列表、反射、IEnumerable 和配置问题