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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Printing a Text file from Qbasic while also archiving the file

Status
Not open for further replies.

jeepo

Technical User
Mar 24, 2003
3
US
I have written a data acquisition system, and right now it creates the text file "data.txt" and I have a batch program where the qbasic program runs and then "copy data.txt lpt1"
Works fine, but now I want to specifically name and save the text file for archiving purposes.

This is what I have:

open "data.txt" for output as #3

Then the batch file copies it to LPT1 outside of Qbasic. But the batch file points specifically to data.txt

What I want:

input "filename"; name$ 'How do I add the ".txt so the operator doesn't have to type it? Or do I even need the .txt?

now how do I get the whole file to the printer within Qbasic? I have seen posts on OPEN "LPT1:BIN" FOR OUTPUT AS
but then that only copies one variable to the printer. Can the whole text file be contained in one varible?

Thanks for all your help!!

Dammit, Jim, I'm an engineer-not a programmer!!
 
OK-Here's an update of what I tried today:

INPUT "What Cartridge"; cart$ (The response I typed was 305)
OPEN cart$ FOR OUTPUT AS #3
OPEN "LPT1" FOR OUTPUT AS #5
PRINT #3 BLAH BLAH BLAH (all my data from the data acquistion, multiple PRINT #3 statements, some strings, some numbers, formatted in tabular output)
CLOSE 1,2,3,4
PRINT #5, cart$
CLOSE 5

Can anyone guess what printed??

"305" on the top of the page-that's it.

If I OPEN "data.txt" FOR OUTPUT AS #3, then all of my data is in a file named data.txt that I view/copy/print many ways. But I want to replace the filename with a user supplied name, so that it has meaning and we have a record of it, in this case, I was hoping for a file named "305" that held all of my data.
I hope I am explaining this clearly enough. Please ask me questions if don't understand what I am trying to do!! I may not understand what I am trying to do!!
 
How about print #3 and lprint of the same data?
input"filename";fn$:f$=fn$+".txt"
These from gwbasic. Ed Fair
Any advice I give is my best judgement based on my interpretation of the facts you supply. Help increase my knowledge by providing some feedback, good or bad, on any advice I have given.
 
INPUT "What is the name of the file?", file$
IF LCASE$(RIGHT$(file$, 4)) <> &quot;.txt&quot; THEN file$ = file$ + &quot;.txt&quot;
 
Thanks for the help!!

I will try LPRINT- I think I was making it harder than it needed to be.

I will try the code to add the .txt
I thought that with strings you couldn't just &quot;+&quot; add something-only numbers

 
1) after
OPEN cart$ FOR OUTPUT AS #3
OPEN &quot;LPT1&quot; FOR OUTPUT AS #5
you can double all your
PRINT #3
lines as
PRINT #5.

2) Or you can skip
OPEN &quot;LPT1&quot; FOR OUTPUT AS #5
part and instead after closing files issue commands
Code:
   cmd$=&quot;copy &quot;+cart$+&quot; lpt1&quot;
   shell cmd$
(that is, same as your batch file did, but from Basic)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top