title: VBA - Create empty array
body: <p>I have a function that takes an array of strings and map each string to a <code>Date</code> instance. The function boils down to the following code. </p>
  
  <pre><code>Private Function ParseDates(dates() As String) As Date()
    Dim res() As Date
    Dim i As Integer
  
    If UBound(dates) &gt;= 0 Then
      ReDim res(UBound(dates)) As Date
    End If
  
  
    For i = LBound(dates) To UBound(dates)
      res(i) = #01/01/2000#
    Next i
    ParseDates = res
  End Function
  </code></pre>
  
  <p>The function works just fine as long as the argument <code>dates</code> is <strong>nonempty</strong>. When <code>dates</code> is empty <code>res</code> is not given a dimension. As a result, the returned value is not enumerable causing to users of this function to crash if the result is enumerated in a loop.</p>
  
  <pre><code>parsedDates = ParseDates(input) 
  For i = 1 To UBound(parsedDates) ' Suscription out of range
    ...
  </code></pre>
  
  <p>How do I instantiate and return an empty array, when dates is empty? </p>
  
  <p>If you call <code>Split("",".")</code> you receive an object with type <code>String(0 to -1)</code>. I need my function to return a object of type <code>Date(0 to -1)</code> as <code>Date()</code> is not an actual array. </p>
  
  <p>I have tried with <code>ReDim res(-1)</code> this causes an <code>Subscript out of range</code> error.</p>