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.

Newcomers DBPro Corner / Write To File Only If Blank

Author
Message
XdFZero
19
Years of Service
User Offline
Joined: 24th Oct 2004
Location:
Posted: 6th May 2006 04:26
Hello,

What I want to be able to do is, open the text file "log.txt" and write on the next line which has nothing on it.

For example, the "log.txt" has the current 2 lines in it:

Log Information 1
Log Information 2

now I want to add to the next line down, without deleting the first one.

I could do this command before I write to it:

open to read 1,"log.txt"
read string 1,Test1$
read string 1,Test2$
read string 1,Test3$
close file 1

and then do:

if Test1$ = ""
write string 1,"Log Information 3"
else
if Test2$ = ""
write string 1,"Log Information 3"
else
if Test3$ = ""
write string 1,"Log Information 3"
endif
endif
endif

however, this does work, but i am planning to have upto 40 lines.... and it would be easier to just find out if the line has nothin in it or not, and write if its free without doing this whole verfication....

Is their such command to do so?

Thanks you for your time.

Apperciate it!

I iz n00b
TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 6th May 2006 08:50 Edited at: 6th May 2006 08:51
Simply use a string array:



I've just typed this in from memory so it's not been tested in DB. Should point you in the right direction though even if there is the odd error...

TDK_Man

MartinS
18
Years of Service
User Offline
Joined: 15th Dec 2005
Location: Rochester, NY
Posted: 7th May 2006 09:48
Are you using DarkBASIC Classic or Pro? In DarkBASIC Professional, the file must not exist, so therefore your code wouldn't work. I'm not sure about DB Classic, though.

Martin

TDK
Retired Moderator
21
Years of Service
User Offline
Joined: 19th Nov 2002
Location: UK
Posted: 7th May 2006 19:24
Quote: " Are you using DarkBASIC Classic or Pro? In DarkBASIC Professional, the file must not exist, so therefore your code wouldn't work. I'm not sure about DB Classic, though."


Is that regarding my code snippet?

If so, you should note the line:

Delete File "log.txt"

just before the Open to Write.

And the file must not already exist rule applies to both DBP and DBC.

TDK_Man

MartinS
18
Years of Service
User Offline
Joined: 15th Dec 2005
Location: Rochester, NY
Posted: 7th May 2006 19:56
Sorry, TDK. No, I wasn't regarding your post.

Login to post a reply

Server time is: 2024-09-24 23:32:00
Your offset time is: 2024-09-24 23:32:00