Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you feed something that VBScript can use as a string to .OpenTextFile, the method will try to open a file and perhaps throw a "file not found" error.</p> <pre><code>&gt;&gt; strInputPath1 = "C:\test" &amp; "\" &amp; "css" &amp; "\" &amp; "main.css" &gt;&gt; WScript.Echo strInputPath1 &gt;&gt; set f = goFS.OpenTextFile(strInputPath1,1) &gt;&gt; C:\test\css\main.css Error Number: 76 Error Description: Path not found </code></pre> <p>To get an "Invalid procedure call" error, you have to pass something sinister, e.g. an Empty value:</p> <pre><code>&gt;&gt; strInputPath1 = Empty &gt;&gt; set f = goFS.OpenTextFile(strInputPath1,1) &gt;&gt; Error Number: 5 Error Description: Invalid procedure call or argument </code></pre> <p>These facts make it highly probable that you</p> <ul> <li>either changed the content of the variable strInputPath1 between its initialization and its use in .OpenTextFile()</li> <li>or initialized a variable X and used a variable Y (Y &amp; X may be variations of "strInputPath1")</li> <li>or initialized and used two variables of the same name in different scopes (~Functions/Subs)</li> </ul> <p>Starting your scripts with "Option Explicit" will reduce the risk of such blunders.</p> <p><strong>Added wrt "got the fso named wrong" comment:</strong></p> <p>As VBScript's error messages are often hard to interpret/understand, this may be a good opportunity to reflect on "What can go wrong? What will VBScript tell me about the problem? What should I do to fix the error? How can I avoid it in the future?"</p> <p>Given a stringy first parameter and a typo (=> empty variable) in goFS:</p> <pre><code>&gt;&gt; strInputPath1 = "C:\test" &amp; "\" &amp; "css" &amp; "\" &amp; "main.css" &gt;&gt; set f = goSF.OpenTextFile(strInputPath1,1) &gt;&gt; Error Number: 424 Error Description: Object required </code></pre> <p>Stands to reason: Trying to call a method (. operator) without an object on the left of the dot is a no-no.</p> <p>Let's Set the evil goSF to an object:</p> <pre><code>&gt;&gt; Set goSF = New RegExp &gt;&gt; set f = goSF.OpenTextFile(strInputPath1,1) &gt;&gt; Error Number: 438 Error Description: Object doesn't support this property or method </code></pre> <p>Still no "invalid procedure call or argument" error. As goSF now is a RegExp, let's ignore the specific method(name) - OpenTextFile() - and see what happens if we mess up the call:</p> <pre><code>&gt;&gt; WScript.Echo TypeName(goSF) &gt;&gt; Set ms = goSF.Execute() &gt;&gt; IRegExp2 Error Number: 450 Error Description: Wrong number of arguments or invalid property assignment &gt;&gt; Set ms = goSF.Execute(Null) &gt;&gt; Error Number: 13 Error Description: Type mismatch </code></pre> <p>So my claim still stands. The error "Invalid procedure call or argument" was caused by feeding Empty to the method .OpenTextFile() called on a valid FSO.</p>
    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.
 

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