2

I have an array that looks like this:

 students1 = Array(423.5482, 425.6641)

Now I would like to get the length of this array. However, if I try this:

 MsgBox(students1.Length)

I get the error that an object is required. Any thoughs on how I can get the length?

Edward de Goeij
  • 87
  • 1
  • 1
  • 5

1 Answers1

11

Use UBound and and Lbound

MsgBox Ubound(students1)-Lbound(students1)+1
Scott Craner
  • 148,073
  • 10
  • 49
  • 81
  • 1
    This will not work on dynamic arrays because UBound() will error out – George Robinson Jun 20 '20 at 21:42
  • This question was not about a dynamic array but a set array. – Scott Craner Jun 21 '20 at 15:33
  • The Answer code is correct ONLY IN THE CASE THE ARRAY IS DEFINED AND NON-EMPTY. If you really want to generically get the size of an Array, then here is a robust solution that handles all the edge cases: https://stackoverflow.com/questions/30574814/get-length-of-array/68614881#68614881 – chaotic3quilibrium Aug 02 '21 at 12:30