在 Excel VBA 中初始化数组 - 出现错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/16457737/
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
Initializing Array in Excel VBA - getting error
提问by Question Everything
In the microsoft site:
在微软网站上:
http://msdn.microsoft.com/en-us/library/vstudio/wak0wfyt.aspx#BKMK_DeclaringAnArray
http://msdn.microsoft.com/en-us/library/vstudio/wak0wfyt.aspx#BKMK_DeclaringAnArray
It says I can initialize an array like this:
它说我可以像这样初始化一个数组:
Dim doubles = {1.5, 2, 9.9, 18}
But I'm getting error:
但我收到错误:
Compile error: Expected: end of statement
And it points to the equals sign. I'm merely copy-pasting, what's wrong here?
它指向等号。我只是复制粘贴,这里有什么问题?
回答by glh
This would work in vb or vb.net but not vba. You need to initialise this in two steps.
这适用于 vb 或 vb.net 但不适用于 vba。您需要分两步进行初始化。
Dim doubles
doubles = array(1.5, 2, 9.9, 18)