0

I'm trying to create an array of integers, but am having a tough time understanding how to first instantiate and check if it's empty. I've done the following, with the array definition tweaked here and there.

Dim months_array() As Variant

If IsEmpty(months_array) Then `Returns False
    MsgBox "Empty"
Else
    ReDim Preserve months_array(1 To size_months_array)
    months_array(UBound(months_array)) = month_iter
    size_months_array = size_months_array + 1
End If

Why does the If statement return false after the definition of the object? Would the best way to check if it's empty be to see if len == 0?

simplycoding
  • 2,770
  • 9
  • 46
  • 91
  • @GSerg any reason why `IsEmpty(months_array)` would be returning `False`? I'm stumped as to what's happening – simplycoding Aug 19 '19 at 18:15
  • 1
    `IsEmpty` detects if a `Variant` contains a special value, `Empty`. `IsNull` detects if a `Variant` contains a special value, `Null` (try `a = Empty` or `a = Null` in the editor, they will be highlighted as keywords). An array is empty according to everyday logic, but it's not a `Variant` variable containing the special value `Empty`. – GSerg Aug 19 '19 at 18:27

0 Answers0