Solved

VBScript Error: Invalid Procedure call or argument

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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This article will show, step by step, how to integrate R code into a R Sweave document
When we want to run, execute or repeat a statement multiple times, a loop is necessary. This article covers the two types of loops in Python: the while loop and the for loop.
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

730 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