Important alert: (current site time 7/16/2013 12:04:46 AM EDT)
 

VB icon

Write to File

Email
Submitted on: 3/17/2000
By: Woody Woodland  
Level: Advanced
User Rating: By 5 Users
Compatibility: ASP (Active Server Pages)
Views: 32822
 
     Writes to a file, jsut change a few things and there you go!
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
 
Terms of Agreement:   
By using this code, you agree to the following terms...   
  1. You may use this code in your own programs (and may compile it into a program and distribute it in compiled format for languages that allow it) freely and with no charge.
  2. You MAY NOT redistribute this code (for example to a web site) without written permission from the original author. Failure to do so is a violation of copyright laws.   
  3. You may link to this code from another website, but ONLY if it is not wrapped in a frame. 
  4. You will abide by any additional copyright restrictions which the author may have placed in the code or code's description.
				
'**************************************
' Name: Write to File
' Description:Writes to a file, jsut change a few things and there you go!
' By: Woody Woodland
'
'This code is copyrighted and has' limited warranties.Please see http://www.Planet-Source-Code.com/vb/scripts/ShowCode.asp?txtCodeId=6099&lngWId=4'for details.'**************************************

sub saveit
	'create a new Active Data Objects connection
	set conn = server.createobject("ADODB.RecordSet")
	'open the ODBC System DSN
	conn.open "usage",dsn, adOpenKeySet, adLockPessimistic, adCmdTable
	conn.addnew
	conn("email")=Request.Form("email")
	conn("IP")=Request.ServerVariables("REMOTE_ADDR")
	conn("referer")=request.form("referer")
	conn("browser")=Request.ServerVariables("HTTP_USER_AGENT")
	conn("date_time")=now
	conn.update
	conn.close
	set conn = Nothing
end sub
sub query2csv(dsn,sql)
whichname="download/contacts.txt"
myDSN=dsn
mySQL=sql
showblank=""
shownull="<null>"
linestart=chr(34)
lineend=chr(34)
delimiter=chr(34) & "," & chr(34)
delimitersub=""
whichFN=server.mappath(whichname)
Set fstemp = server.CreateObject("Scripting.FileSystemObject")
Set filetemp = fstemp.CreateTextFile(whichFN, true)
' true = file can be over-written if it exists
' false = file CANNOT be over-written if it exists
set conntemp=server.createobject("adodb.connection")
conntemp.open myDSN
set rstemp=conntemp.execute(mySQL)
' this code detects if data is empty
If rstemp.eof then
response.write "No data to convert for SQL statement<br>"
response.write mySQL & "<br>"
connection.close
set connection=nothing
response.end
end if
DO UNTIL rstemp.eof
thisline=linestart
for each whatever in rstemp.fields
 thisfield=whatever.value
 if isnull(thisfield) then
 thisfield=shownull
 end if
 if trim(thisfield)="" then
 thisfield=showblank
 end if
 thisfield=replace(thisfield,delimiter,delimitersub)
 thisline=thisline & thisfield & delimiter
next
tempLen=len(thisline)
tempLenDelim=len(delimiter)
thisline=mid(thisline,1,tempLEN-tempLenDelim) & lineend
filetemp.WriteLine(thisline)
' response.write thisline & "<br>"
rstemp.movenext
LOOP
filetemp.Close
set filetemp=nothing
set fstemp=nothing
rstemp.close
set rstemp=nothing
conntemp.close
set conntemp=nothing
If err.number=0 then
response.write "File was converted sucessfully!<br>"
response.write "Converted file is at <a href='"
response.write whichname & "'>" & whichname & "</a>"
else
 response.write "VBScript Errors Occured!<br>"
 response.write "Error Number=#<b>" & err.number & "</b><br>"
 response.write "Error Desc. =<b>" & err.description & "</b><br>"
 response.write "Help Path =<b>" & err.helppath & "</b><br>"
 response.write "Native Error=<b>" & err.nativeerror & "</b><br>"
 response.write "Error Source =<b>" & err.source & "</b><br>"
response.write "SQL State=#<b>" & err.sqlstate & "</b><br>"
end if
end sub


Other 2 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Advanced category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments

6/27/2001 10:48:12 AMwoah

holy, dang dude thats like 10000 things not writing to a text file, not everyone has sql
(If this comment was disrespectful, please report it.)

 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.