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 Discussion / Appending Files

Author
Message
Quirkyjim
17
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 2nd Dec 2008 03:00
I wrote a file like such:


To write onto another file. However, it's not working. It goes to the line in bold and says that it can't write to a file. I think it means the one in talics though. Please help!

~QJ
BN2 Productions
22
Years of Service
User Offline
Joined: 22nd Jan 2004
Location:
Posted: 2nd Dec 2008 04:48
You can't write to a file that was open to read. You have to open to write first. The problem with appending data, is that the open to write command will create a new file and cause an error if the file exists. To solve this you can a) make a new file and copy all data from the first to the second and then add stuff, or b)open to write at the beginning(of the program) and don't close the file.

Ever notice how in Microsoft word, the word "microsoft" is auto corrected to be "Microsoft" but "macintosh" just gets the dumb red underline?
Quirkyjim
17
Years of Service
User Offline
Joined: 18th Oct 2008
Location: At my computer
Posted: 4th Dec 2008 21:59
DUH!!!


~QJ
TDK
Retired Moderator
23
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 5th Dec 2008 18:17
Quote: "To solve this you can a) make a new file and copy all data from the first to the second and then add stuff, or b)open to write at the beginning(of the program) and don't close the file."


There is a third option too.

At the start of your program, check to see if the file exists. If it does, load all the data into a string array. If it doesn't, then create the file.

During the program, add any new data to the end of the array.

At the end of the program (or any other preferred moment), delete the file, create a new file using the same name and write all the array data to it.

TDK

TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 5th Dec 2008 18:38
TDK!!! You`re back!

TheComet

Peachy, and the Chaos of the Gems

Login to post a reply

Server time is: 2026-07-05 06:00:21
Your offset time is: 2026-07-05 06:00:21