VBA / VB6集合到底是什么? [英] What exactly is the VBA/VB6 Collection?

查看:96
本文介绍了VBA / VB6集合到底是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

对于整数键,索引编制的速度为 O(N),因此它看起来像是一个列表。但是很显然(在无法在VB6每次循环中正确循环浏览键和值)是 O(log(N)) ...也许是一棵基于单链接列表(索引列表元素)的树吗?

For integer keys the speed of indexing is O(N), so it looks like it is a list. But apparently (wqw's comment in Unable to properly loop through keys AND values in a VB6 For Each loop) access time for string keys is O(log(N))... Maybe it is a tree built on top of single-linked list (indexing the list elements)?

我努力获取有关此文档的信息,但我只能找到如何使用 集合 ,永远不会是它的数据模型。

I tried hard to get the documentation about this, but all I can find is how to use the Collection, never what is its data model.

推荐答案

我怀疑您会发现有关VBA.Collection实现细节的很多东西吗? 。 (位于 https ://docs.microsoft.com/zh-cn/office/vba/language/reference/user-interface-help/collection-object )

I doubt you'll find much of anything regarding the implementation details of VBA.Collection. (Official usage reference at https://docs.microsoft.com/en-us/office/vba/language/reference/user-interface-help/collection-object)

一般建议是考虑改用VBScript字典对象。如果您需要访问密钥,请一定使用它。据此,Dictionary在某种程度上也更快:> https://fastexcel.wordpress.com/2012/07/10/comparing-two-lists-vba-udf-shootout-between- linear-search-binary-search-collection-and-dictionary /

The general advice is to consider using the VBScript Dictionary object instead; certainly use that instead if you need access to the keys. According to this, Dictionary is also faster up to a point: https://fastexcel.wordpress.com/2012/07/10/comparing-two-lists-vba-udf-shootout-between-linear-search-binary-search-collection-and-dictionary/

我自己做过的另一种选择是利用.NET Hashtable(引用mscorlib.dll)。与VBScript字典相比,我尚未进行任何性能测试,因此我不值得付出努力(但实现起来很有趣)。 无法在VBA(Excel)中迭代Hashtable

Another alternative I've done myself was to make use of the .NET Hashtable (making reference to mscorlib.dll). I've not done any performance tests of that versus VBScript Dictionary, so I don't if it's worth the effort (but it was fun to implement). An example is at Cannot iterate Hashtable in VBA (Excel).

这篇关于VBA / VB6集合到底是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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