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

0 Members and 1 Guest are viewing this topic.

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
How to dump text into a .txt file?
« 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?

FellippeHeitor

  • Guest
Re: How to dump text into a .txt file?
« Reply #1 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."

Offline johannhowitzer

  • Forum Regular
  • Posts: 118
    • View Profile
Re: How to dump text into a .txt file?
« Reply #2 on: June 26, 2018, 07:37:34 pm »
Thanks!

FellippeHeitor

  • Guest
Re: How to dump text into a .txt file?
« Reply #3 on: June 26, 2018, 07:40:01 pm »
You're welcome! And welcome to the forum!

Offline codeguy

  • Forum Regular
  • Posts: 174
    • View Profile
Re: How to dump text into a .txt file?
« Reply #4 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.
« Last Edit: June 26, 2018, 10:27:07 pm by codeguy »

Offline SMcNeill

  • QB64 Developer
  • Forum Resident
  • Posts: 3972
    • View Profile
    • Steve’s QB64 Archive Forum
Re: How to dump text into a .txt file?
« Reply #5 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.
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!