Page 1 of 1

Empty lines in FileWrite

PostPosted: Wed Feb 14, 2007 2:12 am
by Beppe
I ha ve a problem with the Filewrite action
I use one listbox in order to visualize the content of file.
The rows that i visualize in the listbox introduce some empty lines!


.FUNCTION TO WRITE FILE

DefineVar "[trovata]" "Integer" "" "Local" ""
DefineVar "[elementi]" "String" "" "Local" ""

.read the file
FileRead "[PubDir]bookmark.dat" "ALL" "[elementi]"

.search duplicated element in the file
SearchStr "[%lezione]" "[elementi]" "[trovata]"
If "[trovata]" ">" "0"
AlertBox "Attenzione" "Elemento giĆ  presente nei preferiti"
Else
.append the element
FileWrite "[PubDir]bookmark.dat" "Append" "[%lezione]"
AlertBox "Attenzione" "Lezione aggiunta ai preferiti"
EndIf


.Write the file in the variable
FileRead "[PubDir]bookmark.dat" "ALL" "[booklist]"

the variable [booklist] comes used from the listbox in order to visualize the rows

PostPosted: Wed Feb 14, 2007 5:38 am
by Gaev
Beppe:

Welcome to the NeoBook Forum ...

Try and replace ...
Code: Select all
FileWrite "[PubDir]bookmark.dat" "Append" "[%lezione]"

... with ...
Code: Select all
FileWrite "[PubDir]bookmark.dat" "All" "[elementi][#13][#10][%lezione]"

unfortunately it does not work

PostPosted: Wed Feb 14, 2007 6:05 am
by Beppe
unfortunately it does not work

the result in the list box is:

|Lezione1
(empty line)
|lezione1|lezione2


the wished result is:

lezione1
lezione2
lezione3


without empty lines

PostPosted: Wed Feb 14, 2007 7:53 am
by Gaev
Beppe:

a) Perhaps you can provide details of what the file data looked like BEFORE and AFTER you run this routine ... and the value of [%lezione]

b) The suggested change won't remove empty lines already present in your file from before ... only prevent new ones with each new FileWrite command ... you can use notepad.exe to do a one time cleanup

c) You can also use the StrReplace command to remove extraneous characters ... but it is difficult to see what those characters are from looking at the post ... as it is not possible to tell between spaces ([#32]) and carriage-return/line-feed ([#13][#10]) characters ... but you might try and place this just after the FileRead command ...
Code: Select all
StrReplace "[elementi]" "[#13][#10][#13][#10]" "[#13][#10]" "[elementi]"
... it will replace two consecutive CRLF sequences with just one ... which will work if the empty line does NOT contain real spaces.

PostPosted: Thu Feb 15, 2007 2:08 am
by cp4w
I don't think it is a good idea that you assume the entire "[booklist] as content of your ListBox. File ASCII are less "clean" than we think. I suggest this code:

FileLen "[PubDir]\bookmark.dat" "[Tot]"
If "[Tot]" ">" "0"
Loop "1" "[Tot]" "[N]"
FileRead "[PubDir]\bookmark.dat" "[N]" "[elemento]"
If "[elemento]" "<>" ""
ListBoxAddItem "ListaBox1" "0" "[elemento]"
Endif
EndLoop
EndIf

Ciao
Licia