Author Topic: How to dump text into a .txt file?  (Read 67 times)

How to dump text into a .txt file?
« on: June 26, 2018, 08:18:15 PM »
Hey, thanks for reading.

I know how to write values to binary files, but I would like to create actual text output that I could then copy over to a word processor.  Is there a way to do this easily?

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: How to dump text into a .txt file?
« Reply #1 on: June 26, 2018, 08:35:36 PM »
Open it for OUTPUT and use PRINT:

Code: [Select]
'SAMPLE CODE:
OPEN file$ FOR OUTPUT AS #1
PRINT #1, "This is the first line of my text file"
PRINT #1, "And this is the last."
CLOSE #1

Re: How to dump text into a .txt file?
« Reply #2 on: June 26, 2018, 08:37:34 PM »
Thanks!

Online FellippeHeitor

  • QB64 Developer
  • LET IT = BE
    • QB64.org
Re: How to dump text into a .txt file?
« Reply #3 on: June 26, 2018, 08:40:01 PM »
You're welcome! And welcome to the forum!

Re: How to dump text into a .txt file?
« Reply #4 on: June 26, 2018, 11:25:51 PM »
Open "somerandomtextfile" for binary as c%
_clipboard$=input$(c%,lof(c%))
Close c%

Open your word processing executable. Select paste (usually control-v). Voila.
« Last Edit: June 26, 2018, 11:27:07 PM by codeguy »

Re: How to dump text into a .txt file?
« Reply #5 on: June 27, 2018, 12:00:33 AM »
And, if you're used to working with BINARY, just put a CRLF character onto the end of each line of text.

Instead of:  PUT #1, , text$
Instead:  PUT #1, , text$ + CHR$(13) + CHR$(10) 'For Windows style line endings.