VBA, inline array

為{幸葍}努か 提交于 2021-02-08 13:48:33

问题


Looking to create an inline array in 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:

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)


回答1:


Dim a() As Variant
Dim Length As Integer

a = Array(1,2,3)

Length = UBound(a,1) - LBound(a,1) + 1


来源:https://stackoverflow.com/questions/2784592/vba-inline-array

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!