Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This code doesn't do what you expect:</p> <pre><code>If Dir(SigString) &lt;&gt; "" Then Signature = GetBoiler(SigString) Else Signature = "" End If </code></pre> <p>If you pass an empty string (<code>""</code>) or <code>vbNullString</code> to <code>Dir</code>, it will return the name of the first file in the current directory path (the path returned by <code>CurDir$</code>). So, if <code>SigString</code> is empty, your <code>If</code> condition will evaluate to <code>True</code> because <code>Dir</code> will return a non-empty string (the name of the first file in the current directory), and <code>GetBoiler</code> will be called. And if <code>SigString</code> is empty, the call to <code>fso.GetFile</code> will fail.</p> <p>You should either change your condition to check that <code>SigString</code> isn't empty, or use the <code>FileSystemObject.FileExists</code> method instead of <code>Dir</code> for checking if the file exists. <code>Dir</code> is tricky to use precisely because it does things you might not expect it to do. Personally, I would use <code>Scripting.FileSystemObject</code> over <code>Dir</code> because there's no funny business (<code>FileExists</code> returns <code>True</code> if the file exists, and, well, <code>False</code> if it doesn't). What's more, <code>FileExists</code> expresses the <em>intent</em> of your code much clearly than <code>Dir</code>.</p> <p><strong>Method 1: Check that <code>SigString</code> is non-empty first</strong></p> <pre><code>If SigString &lt;&gt; "" And Dir(SigString) &lt;&gt; "" Then Signature = GetBoiler(SigString) Else Signature = "" End If </code></pre> <p><strong>Method 2: Use the <code>FileSystemObject.FileExists</code> method</strong></p> <pre><code>Dim fso As Object Set fso = CreateObject("Scripting.FileSystemObject") If fso.FileExists(SigString) Then Signature = GetBoiler(SigString) Else Signature = "" End If </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload