Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > VBScript FSO: CreateFile OK, OpenTextFile fails

Reply
Thread Tools

VBScript FSO: CreateFile OK, OpenTextFile fails

 
 
Paul
Guest
Posts: n/a
 
      03-15-2006
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






 
Reply With Quote
 
 
 
 
Bob Lehmann
Guest
Posts: n/a
 
      03-16-2006
What's error 5?

Bob Lehmann

"Paul" <> wrote in message
news:%237J1%...
> 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
>
>
>
>
>
>



 
Reply With Quote
 
 
 
 
Egbert Nierop \(MVP for IIS\)
Guest
Posts: n/a
 
      03-16-2006

"Bob Lehmann" <> wrote in message
news:...
> What's error 5?


Access Denied...

 
Reply With Quote
 
Anthony Jones
Guest
Posts: n/a
 
      03-16-2006

"Egbert Nierop (MVP for IIS)" <> wrote in
message news:...
>
> "Bob Lehmann" <> wrote in message
> news:...
> > What's error 5?

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


 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      03-16-2006
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)"


 
Reply With Quote
 
Bob Barrows [MVP]
Guest
Posts: n/a
 
      03-16-2006
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.


 
Reply With Quote
 
Paul
Guest
Posts: n/a
 
      03-17-2006
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.
>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
CreateFile returns invalid handle value when I use wcscpy in my source... ...need a help. MIUSS C++ 6 02-28-2007 11:06 PM
CreateFile in unmanaged code fails Udo Hoerhold ASP .Net Security 0 06-14-2006 03:10 PM
CreateFile - Read/Write client's Stroage Sean Liong via .NET 247 ASP .Net 3 06-09-2005 12:45 PM
OpenTextFile just hangs jwallison ASP General 2 02-26-2004 07:20 PM
OpenTextFile and logging JT ASP General 4 12-23-2003 05:51 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57