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 / Write to file not working

Author
Message
BlackChaos
16
Years of Service
User Offline
Joined: 2nd May 2010
Location: London
Posted: 8th Nov 2012 12:57
My project is quiet large so it would be hard to post the entirety of it here. But everything has been fine up to the point where I am literally 1k's of line in and a basic function of DBPro seems to stop working. Don't get me wrong I've spent time trying to fix this.

Help!



Ignoring the arrays and anything declared. It simply does not write any files intact I have multiple file writing functions in my program but they have all stopped writing files all of a sudden.

Not sure whats going on, maybe has something to do with permissions on writing file on my PC but I am using windows XP Professional and I haven't changed any setting or installed anything lately.

So i aM BaFt!

Thanks,

No feedback this time just food!

AEngine 2012 Ameadus Project Feedback or Food o0
TheComet
18
Years of Service
User Offline
Joined: 18th Oct 2007
Location: I`m under ur bridge eating ur goatz.
Posted: 8th Nov 2012 13:52 Edited at: 8th Nov 2012 13:53
There are two possibilities.

Possibility #1



This statement is never true. You can test this by doing the good old "insert-a-repeat/until-loop-and-print-it-to-the-screen-because-DBP's-debugger-sucks-ass" method just before that section of code:



Possibility #2

The directory "Settings" doesn't exist.

TheComet

- The codebase
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Nov 2012 13:54
Quote: "Not sure whats going on, maybe has something to do with permissions on writing file on my PC but I am using windows XP Professional and I haven't changed any setting or installed anything lately."


Try a simple demo first. If that works then it's probably a coding issue somewhere. I've just tested a simplified version of your function and it works fine. Here's the code I used:

The Weeping Corpse
14
Years of Service
User Offline
Joined: 19th Sep 2011
Location: United Kingdom
Posted: 8th Nov 2012 22:18 Edited at: 8th Nov 2012 22:54
I guess this is feedback not food but it's incredibly bad practice to hard code file names

Quote: "If File Exist("Settings\Objects.OD") = 1 Then Delete File "Settings\Objects.OD"
//OPen file to write
Open To Write 1,"Settings\Objects.OD"
Write String 1,"This is a test write string""


should be



Now for some food, use Windows search and look for Objects.OD. I suspect the file is being written, just not where you expect it to be.

Also, If you have any other blocks of code that use file 1 for reading\writing make sure they close the file when complete. In other words



Will silently fail if file 1 is already in use elsewhere\previously in your code and wasn't closed.

Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 8th Nov 2012 23:48
Good suggestions.
BlackChaos
16
Years of Service
User Offline
Joined: 2nd May 2010
Location: London
Posted: 9th Nov 2012 11:52 Edited at: 9th Nov 2012 12:00
Thanks some really good advice guy

Quote: "
Quote: "If File Exist("Settings\Objects.OD") = 1 Then Delete File "Settings\Objects.OD"
//OPen file to write
Open To Write 1,"Settings\Objects.OD"
Write String 1,"This is a test write string""

should be

+ Code Snippet
TheFileName$ = "Settings\Objects.OD"

If File Exist(TheFileName$) = 1 Then Delete File TheFileName$
//OPen file to write
Open To Write 1,TheFileName$
Write String 1,"This is a test write string"


Now for some food, use Windows search and look for Objects.OD. I suspect the file is being written, just not where you expect it to be.

Also, If you have any other blocks of code that use file 1 for reading\writing make sure they close the file when complete. In other words

+ Code Snippet

Will silently fail if file 1 is already in use elsewhere\previously in your code and wasn't closed.
"


I think I failed to mention at the start that the "Settings\Objects.OD" file should either exist in a folder that has the origin location of the main .exe unless otherwise changed to a full directory, so I chose the more of a relative location approach. Not certain why the file would be written anywhere else.

Another thing, the array "object(n).num > 0" would be monitored and updated before the file saving function is called. The array is updated with a object number in an empty array index position(I mean the ".num" is checked for 0) every time an object is created and before I save there are 5 existing objects, both in the array and on screen.


Assuming everything I just said was true can anyone think of any other reason?

Otherwise I would have to re-write all my code bottom up :-(

AEngine 2012 Ameadus Project Feedback or Food o0
Green Gandalf
VIP Member
21
Years of Service
User Offline
Joined: 3rd Jan 2005
Playing: Malevolence:Sword of Ahkranox, Skyrim, Civ6.
Posted: 9th Nov 2012 13:15
Quote: "Otherwise I would have to re-write all my code bottom up "


Don't do that! Try to narrow down where it goes wrong. For example, try commenting out large chunks of code that don't seem to be relevant to the problem. If the problem is still present then you can delete those commented chunks. If the problem disappears then you know that the commented code is implicated somehow. Eventually you'll get down to a single section of code which causes the problem - and my guess is that it's a simple error which you can't see at the moment because there's too much code in front of you.

Don't forget to do all this on a separate copy of your whole project - it can be very annoying to delete your only copy of code while bug-hunting.
BlackChaos
16
Years of Service
User Offline
Joined: 2nd May 2010
Location: London
Posted: 12th Nov 2012 19:11
Ok thanks for the advice guys.

I figured it out! after days of toil and staying up late to iron out the bugs.

I tried to write to folders that didn't exist in the current working directory. In fact all I needed to add(Complete different section of code) was to add SET DIR$ ".." to jump one folder up.

Lesson to anyone using the SET DIR function.



AEngine 2012 Ameadus Project Feedback or Food o0

Login to post a reply

Server time is: 2026-07-08 03:48:05
Your offset time is: 2026-07-08 03:48:05