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

0 Members and 1 Guest are viewing this topic.

Offline jackyjoy123

  • Newbie
  • Posts: 2
    • View Profile
How to dump text into a .txt file ?.
« on: March 15, 2021, 11:26:14 am »
Hello,

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?


thanks
jackyjoy

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 #1 on: March 15, 2021, 11:56:09 am »
If you’re used to BINARY files, you can just PUT your text to the file and append a CHR$(10) after it.

text$ = “Hello World”
PUT #1, , text$ + CHR$(10)



A second method is just to open for OUTPUT and then PRINT to the file.

OPEN “temp.txt” FOR OUTPUT AS #1
text$ = “Hello World”
PRINT #1, text$
CLOSE
https://github.com/SteveMcNeill/Steve64 — A github collection of all things Steve!

Offline bplus

  • Global Moderator
  • Forum Resident
  • Posts: 8053
  • b = b + ...
    • View Profile
Re: How to dump text into a .txt file ?.
« Reply #2 on: March 15, 2021, 11:59:13 am »
Many ways to dump text into file:

Code: QB64: [Select]
  1.  
  2. Open "MyFile.txt" For Output As #1
  3. Print #1, "Whatever for line 1"
  4. Print #1, "This for line #2"
  5. Print #1, "ect..."
  6. Print "MyFile.txt is filed."
  7.  
« Last Edit: March 15, 2021, 12:02:47 pm by bplus »