OpenOffice.org Forum at OOoForum.orgThe OpenOffice.org Forum
 
 [Home]   [FAQ]   [Search]   [Memberlist]   [Usergroups]   [Register
 [Profile]   [Log in to check your private messages]   [Log in

Write string array into txt file without empty line at end

 
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API
View previous topic :: View next topic  
Author Message
Programmierer
Newbie
Newbie


Joined: 15 Dec 2010
Posts: 2

PostPosted: Wed Dec 15, 2010 12:36 pm    Post subject: Write string array into txt file without empty line at end Reply with quote

Hi all,

following code works fine. Problem is, that the last line of the file is empfy.
The last line in the text file should be "Line 3: 123" .



Sub Main
Dim iFileNo As Integer
Dim sFilename As String
Dim lSize As Long
Dim lRow As Long
Dim aText(2) As String

aText(0) = "Line 1: abc"
aText(1) = "Line 2: xyz"
aText(2) = "Line 3: 123"

sFilename = "C:\work\data.txt"
iFileNo = FreeFile

Open sFilename For Output As #iFileNo ' Open file (writing mode)

lSize = UBound(aText)
lRow = 0

'Print #iFileNo, "Test-Text Zeile 1" ' Save line
'Print #iFileNo, "Test-Text Zeile 2" ' Save line

do while lRow <= lSize
Print #iFileNo, aText(lRow) ' Save line
lRow = lRow + 1
loop

Close #iFileNo ' Close file

End Sub



Entries in File:
Line 1: abc
Line 2: xyz
Line 3: 123
"last line is empty" Sad
Back to top
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Wed Dec 15, 2010 11:37 pm    Post subject: Reply with quote

Hi,
There is no empty line. Each line is ending with CR+LF characters. That is the normal structure of a text.
Some editors display an empty line to show that the last line has ended with an End Of Line.

In the forum, use the Code button before and after the Basic code that you type.
_________________
Bernard

OpenOffice.org 1.1.5 fr / Apache OpenOffice 4.0.1 / LibreOffice 4.1.0
MS-Windows 7 Home SP1
This forum is spammed, use instead Apache OpenOffice forums
Back to top
View user's profile Send private message Visit poster's website
Programmierer
Newbie
Newbie


Joined: 15 Dec 2010
Posts: 2

PostPosted: Thu Dec 16, 2010 10:36 am    Post subject: Reply with quote

Hi,

thanks for answering. But how can I remove the CR+LF at the last line?
Is there a spezial attribute for the command 'Print'?

I have a special programm which reads that txt-file. It's necessary that the last line is without carriage return / linefeed.
Back to top
View user's profile Send private message
B Marcelly
Super User
Super User


Joined: 12 May 2004
Posts: 1453
Location: France

PostPosted: Thu Dec 23, 2010 4:53 am    Post subject: Reply with quote

See
http://www.oooforum.org/forum/viewtopic.phtml?t=94065&highlight=writestring
_________________
Bernard

OpenOffice.org 1.1.5 fr / Apache OpenOffice 4.0.1 / LibreOffice 4.1.0
MS-Windows 7 Home SP1
This forum is spammed, use instead Apache OpenOffice forums
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    OOoForum.org Forum Index -> OpenOffice.org Macros and API All times are GMT - 8 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group