Solved

VBScript Error: Invalid Procedure call or argument

Posted on 2004-08-03
4
8,272 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 500 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

How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

Question has a verified solution.

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

Introduction: Recently, I got a requirement to zip all files individually with batch file script in Windows OS. I don't know much about scripting, but I searched Google and found a lot of examples and websites to complete my task. Finally, I was ab…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
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 …
The viewer will learn how to user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

726 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