3

I dim a empty array of string, but how can I get whether the array is empty? I have tried below but get no idea.

Sub arrtest()
  Dim myVar() As String
  Debug.Print VarType(myVar)   '8200
  Debug.Print TypeName(myVar)  'String()
  Debug.Print IsEmpty(myVar)   'False
  Debug.Print IsNull(myVar)    'False
  Debug.Print LBound(myVar)    'Error
  Debug.Print UBound(myVar)    'Error
  Debug.Print myVar Is Nothing 'Error
End Sub
johnn
  • 317
  • 1
  • 5
  • 15

1 Answers1

7

Here are two options

If you're checking if the array's been initialized

If (Not myVar) = -1 Then
    'Array has been initialized
End if

If you're checking whether or not it has values. Note: This only works for String Arrays

If Len(Join(myVar)) > 0 Then
    'Array contains values
End if
CaffeinatedMike
  • 1,537
  • 2
  • 25
  • 57