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 / Cant 'Open To Write but can 'Open To Read' ????

Author
Message
JoeCory
10
Years of Service
User Offline
Joined: 19th Sep 2014
Location:
Posted: 3rd Jan 2015 13:15
Hi guys, I'm fairly new to DarkBasic and I'm trying to read and write to a .txt file

this is the code i have so far

Open to Read 1,"Test1.txt"
Open to Write 2,"Test2.txt"

Print File Open(1)
Print File Open(2)

Wait Key

when I run this I get a 1 then a 0 displayed showing that it can open the file that it is reading but not the one that it wants to write to...

very confused and and help will be greatly appreciated.
WickedX
16
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 3rd Jan 2015 18:25
You can't write to a file if it already exist. Delete the file before attempting to write.
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Jan 2015 18:32
Yes, that's almost certainly what's causing the problem. Of course, you won't want to delete it if you need to add to the file rather than write a new one.



Powered by Free Banners
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Jan 2015 18:50
This might do the appending trick [Not tested as I use STYX for writing to files]


WickedX
16
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 3rd Jan 2015 19:02 Edited at: 3rd Jan 2015 19:04
Duplicate deleted.
WickedX
16
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 3rd Jan 2015 19:03 Edited at: 3rd Jan 2015 19:04
Why there isn't a OPEN TO APPEND function is beyond me. Seems like a basic function not to be included. What’s the purpose of MAKE FILE? What can we do with it after it’s made? Delete it!
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Jan 2015 21:19
WickedX - did you try the above?

WickedX
16
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 3rd Jan 2015 22:12 Edited at: 3rd Jan 2015 22:13
Have you? What's the point?
MrValentine
AGK Backer
14
Years of Service
User Offline
Joined: 5th Dec 2010
Playing: FFVII
Posted: 3rd Jan 2015 23:08
WRITE FILE

WickedX
16
Years of Service
User Offline
Joined: 8th Feb 2009
Location: A Mile High
Posted: 3rd Jan 2015 23:16
WRITE FILE File Number, Variable

The file still needs to be open with OPEN TO WRITE which will fail if the file already exist. So again, what's the point?
Green Gandalf
VIP Member
20
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 3rd Jan 2015 23:45 Edited at: 4th Jan 2015 00:02
Use IanM's Matrix1 utilities. They are free and a must have for any DBPro programmer.

From the Matrix1 Help file:

Quote: "OPEN DATAFILE TO APPEND

Syntax

OPEN DATAFILE TO APPEND FileId, Filename$
IsOpen = OPEN DATAFILE TO APPEND( FileId, Filename$ )

Description

Attempts to open the specified file for read-write operation. Any data that exists in this file will be preserved. Any writes that take place will be appended to the data file.

If you do not have the correct access permissions to open the file then the command will fail silently.

If using the function form of this instruction, the function will return 1 if the file is open or 0 otherwise.

If using the command form of this instruction, you can check if the file was successfully opened by using the DATAFILE EXIST() function.
"


But it's quite possible that JoeCory wants none of this.

We seem to be getting very good of late at generating long threads without relevant input from the original poster.



Powered by Free Banners

Login to post a reply

Server time is: 2025-05-11 11:28:06
Your offset time is: 2025-05-11 11:28:06