在数组中存储数组 [英] Storing arrays within arrays

查看:176
本文介绍了在数组中存储数组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Excel VBA中,有没有办法在另一个数组中存储数组?例如,如果我创建了一个称为世界的一维数组和具有各种名称的二维数组,那么可以将每个2D数组存储到世界的每个项目中(不管数组世界可能是多少)?如果是这样,我该怎么做,我如何参考世界中的二维数组中的项目?

In Excel VBA, is there a way to store an array within another array? For instance, if I created a 1-dimensional array called "World" and 2-dimensional arrays with various names, would it be possible to store each 2D array into each item of "World" (however long the array "World" may be)? If so, how could I do this, and how would I refer to the items in the 2D arrays within "World"?

我应该研究使用对象和/或类吗?你怎么做这个或者你有一个好的地方来引用我?我一直在网上看一段时间,还没有找到解决方案。非常感谢任何帮助。

Should I be looking into using objects and/or classes? How do you do this or do you have a good place to reference me to? I have been looking online for some time and haven't found a solution yet. Any help is greatly appreciated.

推荐答案

在我看来,我会使用一个集合。然后,您可以收集集合。集合很好,因为您可以参考密钥并获取相应的值...

In my opinion I would use a collection. You can then have collections of collections. Collections are good because you can referece the "Key" and get the corresponding value...

   Public Function MultiDimensionalCollection() as Collection
       Dim tempColl as Collection
       Set MultiDimensionalCollection = new Collection

       For i = 1 to 100
           Set tempColl = New Collection
           tempColl.Add "Value", "Key-" & i 
           tempColl.Add "Value2", "Key2-" & i
           tempColl.Add "Value3", "Key3-" & i
           MultiDimensionalCollection.Add tempColl, "Key-" & i
       Next i

   End Function

它们与任何东西(对象,范围值等)。只需确保您不复制KEY值,否则将收到错误。让我知道,如果你想要样本代码填充他们从范围或记录集或任何你想要的。谢谢Brian。

You can obviously fill them with anything (objects, range values, etc.). Just make sure you don't duplicate the "KEY" value or you will get an error. Let me know if you want sample code for filling them from ranges or recordsets or whatever you'd like. Thanks, Brian.

这篇关于在数组中存储数组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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