Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Write to a text file ....

Status
Not open for further replies.

hummer010

Technical User
Sep 29, 2000
12
CA
I have a .asp page which selects data from a database using an SQL statement and an ODBC connection.

I need to be able to open a text file, or create it if it doesn't exist, and write data to that text file, one line at a time. I am more familiar with VB. In VB I would have done this:

wFile = 1
Open "C:\temp\myfile.txt" For Output As wFile
Print #wFile, strDatabaseLine
Print #wFile vbCrLf


I would put this in a Do-While Loop Until the Database data was finished. This code doesn't work in VBS. I get an error as follows:


Microsoft VBScript compilation error '800a0401'

Expected end of statement

/create.asp, line 33

Open "C:\Temp\myfile.txt" For Output As wFile
--------------------------^


Obviously I'm doing something wrong. Can anyone tell me how to do this??

Thanks in advance.

Cheers
hummer010
 
Okay. I think I figured out how to open the file. I am using this code:

File = "c:\temp\write.txt"
Set FileObj = Server.CreateObject("Scripting.FileSystemObject")
Set OpenFile = FileObj.OpenTextFile(File)

I don't get any errors from this.

I need to know how to write to the file

Using "Print #OpenFile, strDatabase" returns an error based on the #

What command do I use to write to the file?
 
I have a script that writes to a file, the code to write looks like this:

set f1 = fs.OpenTextFile("c:\VBS\remap.log", ForAppending, true)
f1.writeline("Beginning run on " & now & " --------------")

But this is in a VBS file that I run on my machine, not in an ASP page. I have not written to a file using ASP so I cannot help anymore than this...sorry if I am just wasting space here..

Mike
 
Got it figured out. You're code is right.

File = "c:\temp\write.txt"
Set FileObj = Server.CreateObject("Scripting.FileSystemObject")
Set OpenFile = FileObj.CreateTextFile(File, True)
OpenFile.writeLine strDatabase

Thanks.
 
Can someone tell me how to print the screen to a text file? I am using Windows 2000 and a program called CRT. All I need to do is print the screen to a random text file.

I setup a generic printer in Win2K and selected "Text File" for the port, but it will always prompt for the filename. There must be a better way ??

Thanks in advance!
 
No, There are much easier ways to do that!

I need to use the screen shot to monitor data, such as index files on a unix system, redundancy and such.

Was a good shot tho. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top