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!

Need help with syntax

Status
Not open for further replies.

jd.ford1

Programmer
Oct 19, 2017
6
US
I am writing an ASP page and struggling with the WriteLine command. The SELECT statement works fine, but I want to send the output to a file instead of the display screen

<%@ LANGUAGE="VBScript" %>
<!--#include file="../timeconn.inc" -->

<%

Response.Buffer=True
Response.Clear


Dim objFSO, objTStream
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTStream = objFSO.CreateTextFile("c:\supsvc\Medical\admin\test.txt", True)


SQLStmt = "SELECT * from medtransaction"

objTStream.WriteLine()
objTStream.WriteLine("Need data from SELECT statement to go to file text.txt instead of display screen")
objTStream.WriteLine()

objTStream.Close

Set objTStream = nothing
Set objFSO = nothing

Set RS = Connection.Execute(SQLStmt)

%>


Thanks
JD
 
I am not getting an error with the select statement, the information is displayed on the screen correctly, but I want the info to go to a text file. I can not figure out the WriteLine syntax to do it.

Thanks
 
Chris: Why are you posting a 14 year old thread from another forum about VBA???? It has no relevance here.

jd.ford1: There is nothing wrong with your syntax, that's why I asked if you got an error message. So is the problem that "c:\supsvc\Medical\admin\test.txt" is never getting created or is empty? Or is the problem that it does not contain what you expeceted it to contain?
 
The test.txt file is being created with "Need data from SELECT statement to go to file text.txt instead of display screen" in the actual file and the information from the select statement is being displayed on the screen.

Thanks

 
The test.txt file is being created with "Need data from SELECT statement to go to file text.txt instead of display screen" in the actual file ...
Yes, that's precisely what the code you posted will do. If you want to put other things in the text file, you would add more WriteLine statements.

...and the information from the select statement is being displayed on the screen.
You have posted no code that will display anything on the screen???

But anyhow, whatever method you are using to display things on the screen, replace that (or duplicate it) with WriteLine

 
<%@ LANGUAGE="VBScript" %>
<!--#include file="../timeconn.inc" -->

<%

Response.Buffer=True
Response.Clear

Dim objFSO, objTStream
Set objFSO = Server.CreateObject("Scripting.FileSystemObject")
Set objTStream = objFSO.CreateTextFile("c:\supsvc\Medical\admin\test.txt", True)

SQLStmt = "SELECT * from medtransaction"

objTStream.WriteLine
objTStream.WriteLine"Need data from SELECT statement to go to file text.txt instead of display screen"
objTStream.WriteLine
objTStream.Close

Set objTStream = nothing
Set objFSO = nothing

Set RS = Connection.Execute(SQLStmt)

%>

<html>

<head>
<title></title>

<meta name="Microsoft Theme" content="sumipntg 011">
</head>

<body background="../../../_themes/sumipntg/sumtextb.jpg" bgcolor="#FFFFFF" text="#000066" link="#3333CC" vlink="#666699" alink="#990099"><!--mstheme--><font face="verdana,arial,helvetica">


<div align="center"><center>

<!--mstheme--></font><table border="3" bordercolordark="#003366" bordercolorlight="#C0C0C0">
<tr>
<th><!--mstheme--><font face="verdana,arial,helvetica">Date</th>
<th><!--mstheme--><font face="verdana,arial,helvetica">User</th>
<th><!--mstheme--><font face="verdana,arial,helvetica">UIC</th>
<th><!--mstheme--><font face="verdana,arial,helvetica">DODAAC</th>
<th><!--mstheme--><font face="verdana,arial,helvetica">Unit</th>
<th><!--mstheme--><font face="verdana,arial,helvetica">Scope</th>
<th><!--mstheme--><font face="verdana,arial,helvetica">NDCNO</th>
<th><!--mstheme--><font face="verdana,arial,helvetica">Nomenclature</th>
<th><!--mstheme--><font face="verdana,arial,helvetica">UI</th>
<th><!--mstheme--><font face="verdana,arial,helvetica">Cost</th>
<th><!--mstheme--><font face="verdana,arial,helvetica">Quantity</th>
</tr>
<%
Do While not RS.EOF%>

<tr>
<td><!--mstheme--><font face="verdana,arial,helvetica"><%= RS("date_trans") %>&nbsp;<!--mstheme--></font></td>
<td><!--mstheme--><font face="verdana,arial,helvetica"><%= RS("med_user") %>&nbsp;<!--mstheme--></font></td>
<td><!--mstheme--><font face="verdana,arial,helvetica"><%= RS("med_uic") %>&nbsp;<!--mstheme--></font></td>
<td><!--mstheme--><font face="verdana,arial,helvetica"><%= RS("med_dodaac") %>&nbsp;<!--mstheme--></font></td>
<td><!--mstheme--><font face="verdana,arial,helvetica"><%= RS("med_unit") %>&nbsp;<!--mstheme--></font></td>
<td><!--mstheme--><font face="verdana,arial,helvetica"><%= RS("med_scope") %>&nbsp;<!--mstheme--></font></td>
<td><!--mstheme--><font face="verdana,arial,helvetica"><%= RS("ndcno") %>&nbsp;<!--mstheme--></font></td>
<td><!--mstheme--><font face="verdana,arial,helvetica"><%= RS("nomenclature") %>&nbsp;<!--mstheme--></font></td>
<td><!--mstheme--><font face="verdana,arial,helvetica"><%= RS("ui") %>&nbsp;<!--mstheme--></font></td>
<td><!--mstheme--><font face="verdana,arial,helvetica"><%= RS("cost") %>&nbsp;<!--mstheme--></font></td>
<td><!--mstheme--><font face="verdana,arial,helvetica"><%= RS("med_quantity") %>&nbsp;<!--mstheme--></font></td>

</tr>

<% RS.MoveNext
Loop
%>

</table><!--mstheme--><font face="verdana,arial,helvetica">
</center></div>

<p align="center"><a href="../default.asp">Return to Transactions Page</a></p>

<!--mstheme--></font></body>


</html>
<% Connection.Close %>
 
Why are you posting a 14 year old thread from another forum ....

Because it's an EXAMPLE of how to code, and is EXACTLY how I learnt to code different things. Take the code that is close and learn how to adapt it.

Chris.

Indifference will be the downfall of mankind, but who cares?
Time flies like an arrow, however, fruit flies like a banana.

Never mind this jesus character, stars had to die for me to live.
 
Something like this inside the loop should work (not tested)
Code:
<%
objTStream.WriteLine "Date: " & RS("date_trans")
objTStream.WriteLine "User: " & RS("med_user")
objTStream.WriteLine "UIC: " & RS("med_uic")
objTStream.WriteLine "DODAAC: " & RS("med_dodaac")
objTStream.WriteLine "Unit: " & RS("med_unit")
objTStream.WriteLine "Scope: " & RS("med_scope")
objTStream.WriteLine "NDCNO: " & RS("ndcno")
objTStream.WriteLine "Nomenclature: " & RS("nomenclature")
objTStream.WriteLine "UI: " & RS("ui")
objTStream.WriteLine "Cost: " & RS("cost")
objTStream.WriteLine "Quantity: " & RS("med_quantity")
%>

Of course you need to define objTStream before the loop, and close it after the loop
 
guitarzan,

I would like to personally "Thank You" for the help. Literally copied and paste to my code and it started running like a champ!!! I can not tell you how many hours I have spent trying to make that work. You make it look easy my man. Again thanks

JD

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top