Please visit our sponsor
UNKNOWN '************************************** ' Name: Write to File ' Description:Writes to a file, jsut cha ' nge a few things and there you go! ' By: Woody Woodland ' ' ' Inputs:None ' ' Returns:None ' 'Assumes:None ' 'Side Effects:None 'This code is copyrighted and has limite ' d warranties. 'Please see http://www.Planet-Source-Cod ' e.com/xq/ASP/txtCodeId.6099/lngWId.4/qx/ ' vb/scripts/ShowCode.htm '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="&quot; response.write whichname &amp; &quot;">" & 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