VBScript FSO: CreateFile OK, OpenTextFile fails

P

Paul

In one place in my project, I need to create a text file. Each time it runs
it should overwrite the previous version. I use the following code and it
works fine:

FileLoc = server.MapPath("list.txt")
Set fsTemp = server.CreateObject("Scripting.FileSystemObject")
Set RecordsFile = fsTemp.CreateTextFile(FileLoc,true)
RecordsFile.WriteLine(RecCache)
RecordsFile.Close

In another page in the same project, I need to create a logfile of certain
transactions, so each time it needs to append to the end of the file. This
code results in an error 5.

FileLoc = server.MapPath("DBLog.txt")
Set fsTemp = server.CreateObject("Scripting.FileSystemObject")
Set RecordsFile = fsTemp.OpenTextFile(FileLoc, ForAppending, True)
RecordsFile.WriteLine(strSQL)
RecordsFile.Close

Can you point out what I am doing wrong?

Thanks.
Paul
 
A

Anthony Jones

Egbert Nierop (MVP for IIS) said:
Access Denied...

Access Denied... On Facility 7 (Windows API)

OR

Invalid Procedure call... On Facility 4 where the interface implementor is
VB

OR

Anything else you care to think of... On Facility 4 where the interface is
A.N Other object

:)

My bets on Invalid Procedure Call.

It would be nice not to have to guess, Paul?

Anthony.
 
P

Paul

Sorry, I thought VBScript had a consistent error set.

It returns Error 5-Invalid procedure call or argument

The error occurs on the line "Set RecordsFile = fsTemp.OpenTextFile(FileLoc,
ForAppending, True)"
 
B

Bob Barrows [MVP]

Paul said:
Sorry, I thought VBScript had a consistent error set.

It returns Error 5-Invalid procedure call or argument

The error occurs on the line "Set RecordsFile =
fsTemp.OpenTextFile(FileLoc, ForAppending, True)"

It looks like you've failed to define the ForAppending constant. Add this
line:
Const ForReading = 1, ForWriting = 2, ForAppending = 8
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top