Solved

VBScript Error: Invalid Procedure call or argument

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Having just graduated from college and entered the workforce, I don’t find myself always using the tools and programs I grew accustomed to over the past four years. However, there is one program I continually find myself reverting back to…R.   So …
Whether you’re a college noob or a soon-to-be pro, these tips are sure to help you in your journey to becoming a programming ninja and stand out from the crowd.
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
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.

747 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now