VBScript FSO: CreateFile OK, OpenTextFile fails
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Web Servers reviews > IIS server support > IIS ASP > VBScript FSO: CreateFile OK, OpenTextFile fails




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    VBScript FSO: CreateFile OK, OpenTextFile fails  
Paul


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 01:47 AM

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











[ Post a follow-up to this message ]



    Re: VBScript FSO: CreateFile OK, OpenTextFile fails  
Bob Lehmann


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 01:47 AM

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







[ Post a follow-up to this message ]



    Re: VBScript FSO: CreateFile OK, OpenTextFile fails  
Egbert Nierop \(MVP for IIS\)


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 12:49 PM


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

Access Denied...






[ Post a follow-up to this message ]



    Re: VBScript FSO: CreateFile OK, OpenTextFile fails  
Anthony Jones


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 12:49 PM


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







[ Post a follow-up to this message ]



    Re: VBScript FSO: CreateFile OK, OpenTextFile fails  
Paul


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 10: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)"







[ Post a follow-up to this message ]



    Re: VBScript FSO: CreateFile OK, OpenTextFile fails  
Bob Barrows [MVP]


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-16-06 10: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.







[ Post a follow-up to this message ]



    Re: VBScript FSO: CreateFile OK, OpenTextFile fails  
Paul


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-17-06 01:49 AM

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.
>
>







[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:04 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register