为什么在集合中使用VBA中的数组? [英] Why use arrays in VBA when there are collections?
问题描述
所以,我真诚地问自己是否缺少某些东西?为什么其他人仍然使用数组来存储数据列表?是否只是过去的宿醉?
使用数组而不是集合(或词典)的几个原因:
- 您可以使用
Range(A1:B12)= MyArray
- 集合只能存储唯一键,而数组可以存储任何值
- 集合必须存储一对(键,值),而您可以在数组中存储任何内容
请参阅 Chip Pearson的文章关于数组以更好地理解
更好的问题是为什么人们会使用字典集合(可以,集合是标准的VBA,而你必须导入字典)
many people use extensively arrays in Excel/VBA to store a list of data. However, there is the collection object which in my view is MUCH MUCH more convenient (mainly: don't need to re/define length of the list).
So, I am sincerely asking myself if I am missing something? Why do other people still use arrays to store a list of data? Is it simply a hangover of the past?
Several reasons to use arrays instead of collections (or dictionaries):
- you can transfer easily array to range (and vice-versa) with
Range("A1:B12") = MyArray
- collections can store only unique keys whereas arrays can store any value
- collections have to store a couple (key, value) whereas you can store whatever in an array
See Chip Pearson's article about arrays for a better understanding
A better question would rather be why people would use collections over dictionaries (ok, collections are standard VBA whereas you have to import dictionaries)
这篇关于为什么在集合中使用VBA中的数组?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!