Link to home
Start Free TrialLog in
Avatar of wilkersons
wilkersons

asked on

VBScript Error: Invalid Procedure call or argument

Hi all,
I was trying to run a simple vbscript, in which i open a text file for reading. I tried this simple script and it gives a runtime error 800A0005. It works fine when i replace OpenTextFile with CreateTextFile. So, does that mean i have an older version of the scripting engine or am I missing something.

Dim filesys, testfile
Set filesys = CreateObject("Scripting.FileSystemObject")
Set testfile= filesys.OpenTextFile("c:\somefile.txt",ForReading,True)
testfile.WriteLine "Your text goes here."
testfile.Close  

I have windows xp, vbscript version 5.6.

Thanks in advance
ASKER CERTIFIED SOLUTION
Avatar of cookre
cookre
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of wilkersons
wilkersons

ASKER

Sorry, about the mistake.  I was trying different things, so forgot to change it back to ForWriting.
I get the same error. It gives an error at the third statement.

Dim filesys, testfile
Set filesys = CreateObject("Scripting.FileSystemObject")
Set testfile= filesys.OpenTextFile("c:\somefile.txt",ForWriting,True)
testfile.Close
WScript.echo "Finished"

Hi cookre,
I was able to solve the problem.

Dim filesys, testfile
Constant ForWriting = 2
Set filesys = CreateObject("Scripting.FileSystemObject")
Set testfile= filesys.OpenTextFile("c:\somefile.txt",ForWriting,True)
testfile.Close
WScript.echo "Finished"


Needed to define the value for "ForWriting"

Thanks for your immediate response.