VBA,内联数组
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/2784592/
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
VBA, inline array
提问by Mike
Looking to create an inline array in Visual Basic for Applications
希望在 Visual Basic for Applications 中创建内联数组
Something like this would be cool:
像这样的东西会很酷:
Dim a() as Integer
set a = {1,2,3}
In Java, this would be the equivalent functionality:
在 Java 中,这将是等效的功能:
int a[] = {1,2,3};
Also, bonus points if you can tell me how to find its length afterwards (without needing to hard code it, as all the examples my Googling have uncovered)
另外,如果您能告诉我之后如何找到它的长度,则加分(无需对其进行硬编码,因为我的谷歌搜索已发现所有示例)
(please don't tell me to Google it. I normally don't use vb, and I'm discovering that every result for a vb question on Google is answered terribly. ex, hard coding values)
(请不要告诉我谷歌它。我通常不使用 vb,我发现谷歌上 vb 问题的每个结果都得到了可怕的回答。例如,硬编码值)
回答by Lance Roberts
Dim a() As Variant
Dim Length As Integer
a = Array(1,2,3)
Length = UBound(a,1) - LBound(a,1) + 1