QB64.org Forum

Active Forums => QB64 Discussion => Topic started by: johannhowitzer on June 26, 2018, 07:18:15 pm

Title: How to dump text into a .txt file?
Post by: johannhowitzer on June 26, 2018, 07: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?
Title: Re: How to dump text into a .txt file?
Post by: FellippeHeitor on June 26, 2018, 07:35:36 pm
Open it for OUTPUT and use PRINT:

Code: QB64: [Select]
  1. 'SAMPLE CODE:
  2. OPEN file$ FOR OUTPUT AS #1
  3. PRINT #1, "This is the first line of my text file"
  4. PRINT #1, "And this is the last."
Title: Re: How to dump text into a .txt file?
Post by: johannhowitzer on June 26, 2018, 07:37:34 pm
Thanks!
Title: Re: How to dump text into a .txt file?
Post by: FellippeHeitor on June 26, 2018, 07:40:01 pm
You're welcome! And welcome to the forum!
Title: Re: How to dump text into a .txt file?
Post by: codeguy on June 26, 2018, 10: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.
Title: Re: How to dump text into a .txt file?
Post by: SMcNeill on June 26, 2018, 11:00:33 pm
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.