vba 创建数据对象数组的数组?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4326481/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Creating an array of arrays of data objects?
提问by sooprise
I have a data object
我有一个数据对象
I also have arrays of these data objects
我也有这些数据对象的数组
I want to put these arrays of data objects into another array
我想将这些数据对象数组放入另一个数组中
Dim ArrayOfDataObjects1(10) as new DataObject
Dim ArrayOfDataObjects2(10) as new DataObject
Dim ArrayOfDataObjects3(10) as new DataObject
'Now, I want to put all of these into another array, how can I?
Thanks!
谢谢!
edit: I know I need to create another array with size 3, but what type do I define the array as?
编辑:我知道我需要创建另一个大小为 3 的数组,但是我将数组定义为什么类型?
回答by Dr. belisarius
If you are not concerned with type-safety, you could use Variant. Example in Excel VBA:
如果您不关心类型安全,则可以使用 Variant。Excel VBA 中的示例:
Sub a()
Dim ArrayOfDataObjects1(10) As Worksheet
Dim ArrayOfDataObjects2(10) As Worksheet
Dim ArrayOfDataObjects3(10) As Worksheet
Dim arr(3) As Variant
Set ArrayOfDataObjects1(1) = ActiveSheet
arr(1) = ArrayOfDataObjects1
arr(2) = ArrayOfDataObjects2
arr(3) = ArrayOfDataObjects3
MsgBox arr(1)(1).Name
End Sub