VBA集合:键列表 [英] VBA collection: list of keys

查看:119
本文介绍了VBA集合:键列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我向VBA集合添加一些值后,是否有任何方法保留所有键的列表?

After I add some values to the VBA collection, is there any way to retain the list of all keys?

例如

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"

我知道如何保留字符串列表:

I know how to retain the list of strings:

first string
second string
third string


b $ b

再次:是否有任何方法保留密钥?

Once again: is there any way to retain the keys?

first key
second key
third key

注意:通过AutoCAD 2007使用VBA

Note: I'm using VBA through AutoCAD 2007

推荐答案

我不认为这是可能的香草集合,而不存储在独立数组中的键值。最简单的替代方法是添加一个引用到Microsoft Scripting Runtime&使用更有效的字典;

I don't thinks that possible with a vanilla collection without storing the key values in an independent array. The easiest alternative to do this is to add a reference to the Microsoft Scripting Runtime & use a more capable Dictionary instead;

Dim coll As New Dictionary
...
Dim K As Variant
For Each K In coll.Keys
    debug.print "Key: " & K , "Value: " & coll.Item(K)
Next

这篇关于VBA集合:键列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆