Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

VBScript Error: Invalid Procedure call or argument

Posted on 2004-08-03
4
Medium Priority
?
8,430 Views
Last Modified: 2012-06-22
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
0
Comment
Question by:wilkersons
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 22

Accepted Solution

by:
cookre earned 1500 total points
ID: 11709733
You open it as ForReading, then try to write to it.

In the case of CreateTextFile(), the second parm is a boolean, and whatever the value of ForReading is, Create() is happy.
0
 

Author Comment

by:wilkersons
ID: 11709968
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"

0
 

Author Comment

by:wilkersons
ID: 11710766
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.
0
 
LVL 6

Expert Comment

by:DominicCronin
ID: 11777370
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

How to remove superseded packages in windows w60 or w61 installation media (.wim) or online system to prevent unnecessary space. w60 means Windows Vista or Windows Server 2008. w61 means Windows 7 or Windows Server 2008 R2. There are various …
If you haven’t already, I encourage you to read the first article (http://www.experts-exchange.com/articles/18680/An-Introduction-to-R-Programming-and-R-Studio.html) in my series to gain a basic foundation of R and R Studio.  You will also find the …
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question