Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Writing text to a file

Author
Message
FieldDoc
23
Years of Service
User Offline
Joined: 30th May 2003
Location: London, UK
Posted: 15th Sep 2003 17:31
How can I write text to a .txt file using DBPro? I am thinking of adding a log file you see. I have tried this (thinking that it would create a simple .txt file called 'log' that contains the word "testing" in it). Unfortunately, I just get a blank .txt file called log. How do I do this?



Kendor
23
Years of Service
User Offline
Joined: 31st Jan 2003
Location: Malta
Posted: 15th Sep 2003 17:36 Edited at: 15th Sep 2003 17:37
just remove



when you open to write a file, it is automatically created
Mentor
23
Years of Service
User Offline
Joined: 27th Aug 2002
Location: United Kingdom
Posted: 15th Sep 2003 17:43
don`t make the file, all that does is make a blank file, do this

if file exist("logfile.txt") then delete file "logfile.txt"
open to write 1,"logfile.txt"
a$="test"
write string 1,a$
close 1

writes the file, and to read it back just do

open to read 1,"logfile.txt"
while file end()=0
read string 1,a$
print a$
endwhile
close 1

you must always close a file when you have finished with it, for one thing, if you don`t and you just wrote data and then close the program the data will still be in the buffer and may not get written to the file on the drive, so you would lose it, other than that, that is all you need to do, if you intend it be the log for fatal errors in the code then note that you may not get any data in the file since the program will not close the file properly and lose whatever was written, cheers.

Mentor.

Login to post a reply

Server time is: 2026-07-26 05:02:19
Your offset time is: 2026-07-26 05:02:19