Receive vector size

Asked

Viewed 7,019 times

6

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

I searched some things but could not locate anything. How can I recover this value?

  • vetor.Length doesn’t work?

  • 1

    @Felipeavelar, in the case of VBA, the vector is not an object. There are no methods or attributes that you can access to, for example, get the size.

1 answer

4


The array size can be obtained using the function Ubound. 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 show 1 (the last accessible index) and not 2 (the vector size).

Therefore, to know the size, just add + 1 (Msgbox Ubound(s) + 1)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.