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 file problem !

Author
Message
maicl
19
Years of Service
User Offline
Joined: 19th Jun 2007
Location:
Posted: 28th May 2010 21:05 Edited at: 28th May 2010 21:07
Hi everybody ..

When I write something like this code :



I find , when I open the text file , a blank line at the end of the file ..
This causes a lot of problems to me ..
so , I there any way to avoid writing this blank line ??
The Slayer
Forum Vice President
16
Years of Service
User Offline
Joined: 9th Nov 2009
Playing: (Hide and) Seek and Destroy on my guitar!
Posted: 28th May 2010 21:40 Edited at: 28th May 2010 21:45
Quote: "a blank line at the end of the file .."

What exactly do you mean by that?
When I run your code, it writes from 1 to 10, and that's it...?

{EDIT} Hum, I see what you mean. You're saying that the cursor leaves an open line when you go down with the cursorkeys, right?

Cheers

Slayer rules!!! Yeaaah, man!
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 28th May 2010 21:53 Edited at: 28th May 2010 22:04
What he/she (you never know) means is there's a new line left after the writing. You don't have a lot of access with DBP stock commands, but if you grab IanM's Matrix Plugin mainly the datafile's one (Matrix1Util_22) you can resize the file to get rid of the newline. So something like this (not tested):



These plugins are very useful: The Matrix1Utils plugins collection

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
IanM
Retired Moderator
23
Years of Service
User Offline
Joined: 11th Sep 2002
Location: In my moon base
Posted: 28th May 2010 22:15
I was going to post a few links to the helpfiles for one or two commands, but realised that the help is a little crappy ... so I'll explain here instead.

When you use the WRITE DATAFILE STRING command, the command will automatically write out a line ending - what ever you have that line ending set to - and that's the small problem with Sasuke's code example. The line ending doesn't have to be two bytes in size.

What you can do instead is to use the WRITE DATAFILE DATASTRING on your very last string, which will write out the string without any terminating characters.



... or you can just ignore the 'blank line' at the end of the file, which only depends on whether your text editor treats the line-ending as a separator or a terminator (notepad/wordpad treat it as a separator).

maicl
19
Years of Service
User Offline
Joined: 19th Jun 2007
Location:
Posted: 28th May 2010 23:13 Edited at: 28th May 2010 23:14
The Slayer :
Yes , that's what I mean .

Sasuke :
Thanks .. It works very well

IanM :
Do you mean that maybe the ending line in my system is different in size from other systems ??

I Checked your example , but in my program , I have to write more than one line a loop , so your example doesn't work as I want .
Any way , I thought about another solution , If there is a way to get the size of the ending line and then use it along with Sasuke example , I think It will work well with any system

IanM , really I'm glad for your replay .. thank you .

And guys , I'm very sorry for my bad language
Sasuke
20
Years of Service
User Offline
Joined: 2nd Dec 2005
Location: Milton Keynes UK
Posted: 28th May 2010 23:49
Quote: "I Checked your example , but in my program , I have to write more than one line a loop , so your example doesn't work as I want."


Just check if it's the last loop and swap the last line for WRITE DATAFILE DATASTRING:



Also this would be far more efficient than getting the size of the file, getting the blank line size and resizing the file.

A dream is a fantasy, if you achieve that fantasy it was never a dream to begin with.
maicl
19
Years of Service
User Offline
Joined: 19th Jun 2007
Location:
Posted: 29th May 2010 00:28
Now it's working ..

thanks ..
Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 29th May 2010 00:46 Edited at: 29th May 2010 00:47
A few alternatives:

Removing the last terminating characters afterwards:


Using your own customized write/read commands:


Though it might not be as fast as a plug-in...

[EDIT] Seems you figured it out. I guess I'll leave these snippets for future reference then.

Cheers!
Sven B

slyvnr
16
Years of Service
User Offline
Joined: 2nd Nov 2009
Location: Texas
Posted: 7th Jun 2010 18:04
With my files I always do a check for blank lines just in case something happened.

I usually also use "line identifiers" that help define what the line is used for i.e. D for data line, T for generic text, M for menu item, etc.




Slyvnr

Slyvnr

Login to post a reply

Server time is: 2026-07-25 08:29:50
Your offset time is: 2026-07-25 08:29:50