Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VBA, inline array

Tags:

arrays

vba

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)

like image 229
Mike Avatar asked May 06 '10 21:05

Mike


1 Answers

Dim a() As Variant
Dim Length As Integer

a = Array(1,2,3)

Length = UBound(a,1) - LBound(a,1) + 1
like image 87
Lance Roberts Avatar answered Oct 22 '22 16:10

Lance Roberts