IIS ASP - VBScript FSO: CreateFile OK, OpenTextFile fails

This is Interesting: Free IT Magazines  
Home > Archive > IIS ASP > March 2006 > VBScript FSO: CreateFile OK, OpenTextFile fails





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author VBScript FSO: CreateFile OK, OpenTextFile fails
Paul

2006-03-15, 8:47 pm

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






Bob Lehmann

2006-03-15, 8:47 pm

What's error 5?

Bob Lehmann

"Paul" <nospam@mydomain.com> wrote in message
news:%237J1%23uISGHA.5500@TK2MSFTNGP12.phx.gbl...
> 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
>
>
>
>
>
>



Egbert Nierop \(MVP for IIS\)

2006-03-16, 7:49 am


"Bob Lehmann" <nospam@dontbotherme.zzz> wrote in message
news:O3OuOgJSGHA.4616@TK2MSFTNGP10.phx.gbl...
> What's error 5?


Access Denied...

Anthony Jones

2006-03-16, 7:49 am


"Egbert Nierop (MVP for IIS)" <egbert_nierop@nospam.invalid> wrote in
message news:ufstH8MSGHA.4920@tk2msftngp13.phx.gbl...
>
> "Bob Lehmann" <nospam@dontbotherme.zzz> wrote in message
> news:O3OuOgJSGHA.4616@TK2MSFTNGP10.phx.gbl...
>
> 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.


Paul

2006-03-16, 5:52 pm

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)"


Bob Barrows [MVP]

2006-03-16, 5:52 pm

Paul wrote:
> 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

--
Microsoft MVP -- ASP/ASP.NET
Please reply to the newsgroup. The email account listed in my From
header is my spam trap, so I don't check it very often. You will get a
quicker response by posting to the newsgroup.


Paul

2006-03-16, 8:49 pm

Bob,

That was it. Works now. Thank you!!

Paul

> It looks like you've failed to define the ForAppending constant. Add this
> line:
> Const ForReading = 1, ForWriting = 2, ForAppending = 8
>
> --
> Microsoft MVP -- ASP/ASP.NET
> Please reply to the newsgroup. The email account listed in my From
> header is my spam trap, so I don't check it very often. You will get a
> quicker response by posting to the newsgroup.
>
>



Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com