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/Reading Files- What's going on?

Author
Message
KenGames
11
Years of Service
User Offline
Joined: 22nd Sep 2013
Location: United States
Posted: 6th Jun 2015 01:33
I've had a bit of experience in writing and reading files before, I used to do it all the time in C# XNA, but now in DBPro(which is much easier btw) I've come across a strange issue. Assuming the directory is the standard project directory, this code sample when run fails to write to the file. If I open the file with notepad it is empty. What am I missing here???? -It seems simple enough.



In the sample above, it creates and writes to a file. Then displays a text holding the contents of the file(which results in empty).
WickedX
16
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 6th Jun 2015 03:14 Edited at: 6th Jun 2015 03:21
Make File is a useless function. All it does is create an empty file. Open file will create the file if it does not already exist. Since you have created the file with Make File it cannot be accessed to write. Try this instead.

KenGames
11
Years of Service
User Offline
Joined: 22nd Sep 2013
Location: United States
Posted: 6th Jun 2015 03:26
Ah, thanks. Would not have guessed that Make File was not necessary.
Ortu
DBPro Master
17
Years of Service
User Offline
Joined: 21st Nov 2007
Location: Austin, TX
Posted: 6th Jun 2015 05:56
also note that open to write will silently fail without error if the file already exists, it will not append. if you want to append you will need to read it, delete it, open to write and write it back out again along with anything new

Attila
FPSC Reloaded TGC Backer
20
Years of Service
User Offline
Joined: 17th Aug 2004
Location:
Posted: 6th Jun 2015 14:38 Edited at: 12th Jun 2015 00:28
The function append_to_file will append a line to an existing file. If the file does not exist it will create a new file.

Login to post a reply

Server time is: 2025-08-09 02:29:49
Your offset time is: 2025-08-09 02:29:49