title: Iterate ArrayList in for loop
body: <p>I have a function that makes of a <code>ArrayList</code> in vba. I try to iterate through it, using <code>for</code> loop, but I get an error. I'm not sure what use as a <code>LBound</code> and <code>UBound</code> and I can't use either of those functions on the <code>ArrayList</code>.</p>
  
  <pre><code>Function test(dataArray() As Double)
  
      Dim i As Long
  
  
      Dim arr As Object
      Set arr = CreateObject("System.Collections.ArrayList")
  
      For i = LBound(dataArray) To UBound(dataArray)
          arr.Add dataArray(i)
      Next
  
      arr.Sort
  
      For i = 1 To arr.Count
         If arr(i) &lt;= 10000 Then 'error
            ...
         End If
      Next
  
  End Function
  </code></pre>
  
  <p>I get a <code>index out of range, index must be positive and should not exceed the collection's size</code> error inside the cycle. How would I iterate through the <code>ArrayList</code> without errors inside <code>for</code> cycle?</p>