Source language: Translate to:

Empty lines in FileWrite

Questions about using NeoBook's scripting language

Moderator: Neosoft Support

Empty lines in FileWrite

Postby Beppe » Wed Feb 14, 2007 2:12 am

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
Beppe
 
Posts: 4
Joined: Tue Feb 13, 2007 6:22 am

Postby Gaev » Wed Feb 14, 2007 5:38 am

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]"
User avatar
Gaev
 
Posts: 3735
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

unfortunately it does not work

Postby Beppe » Wed Feb 14, 2007 6:05 am

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
Beppe
 
Posts: 4
Joined: Tue Feb 13, 2007 6:22 am

Postby Gaev » Wed Feb 14, 2007 7:53 am

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.
User avatar
Gaev
 
Posts: 3735
Joined: Fri Apr 01, 2005 7:48 am
Location: Toronto, Canada

Postby cp4w » Thu Feb 15, 2007 2:08 am

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
cp4w
 
Posts: 533
Joined: Sun Apr 03, 2005 4:37 pm
Location: Great Neck, NY


Return to NeoBook Action Commands

Who is online

Users browsing this forum: No registered users and 2 guests

cron