title: How to check for empty array in vba macro
body: <p>I want to check for empty arrays. Google gave me varied solutions but nothing worked. Maybe I am not applying them correctly.</p>
  
  <pre><code>Function GetBoiler(ByVal sFile As String) As String
  'Email Signature
      Dim fso As Object
      Dim ts As Object
      Set fso = CreateObject("Scripting.FileSystemObject")
      Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
      GetBoiler = ts.ReadAll
      ts.Close
  End Function
  
  Dim FileNamesList As Variant, i As Integer
  ' activate the desired startfolder for the filesearch
  FileNamesList = CreateFileList("*.*", False) ' Returns File names
  ' performs the filesearch, includes any subfolders
  ' present the result
  ' If there are Signatures then populate SigString
  Range("A:A").ClearContents
  For i = 1 To UBound(FileNamesList)
      Cells(i + 1, 1).Formula = FileNamesList(i)
  Next i
  
  SigString = FileNamesList(3)
  
  If Dir(SigString) &lt;&gt; "" Then
      Signature = GetBoiler(SigString)
  Else
      Signature = ""
  End If
  </code></pre>
  
  <p>Here if <code>FileNamesList</code> array is empty, <code>GetBoiler(SigString)</code> should not get called at all. When <code>FileNamesList</code> array is empty, <code>SigString</code> is also empty and this calls <code>GetBoiler()</code> function with empty string. I get an error at line </p>
  
  <pre><code>Set ts = fso.GetFile(sFile).OpenAsTextStream(1, -2)
  </code></pre>
  
  <p>since <code>sFile</code> is empty. Any way to avoid that?</p>