Receive vector size

5

I would like to know how I get the size of my vector in VBA.

I researched some things but could not locate anything. How can I retrieve this value?

    
asked by anonymous 25.06.2015 / 19:11

1 answer

4

The size of the array can be obtained by using the UBound function. Note, however, that this function does not return the vector size, but the last accessible index.

See the example below:

Sub teste()
  Dim s(1) As String    
  s(0) = "L"
  s(1) = "B"
  MsgBox UBound(s)
End Sub

MsgBox UBound (s) will display 1 (the last accessible index) and not 2 (the size of the vector).

So, to know the size, just add + 1 (MsgBox UBound (s) + 1)

    
25.06.2015 / 19:18