| View previous topic :: View next topic |
| Author |
Message |
Programmierer Newbie

Joined: 15 Dec 2010 Posts: 2
|
Posted: Wed Dec 15, 2010 12:36 pm Post subject: Write string array into txt file without empty line at end |
|
|
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"  |
|
| Back to top |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
Posted: Wed Dec 15, 2010 11:37 pm Post subject: |
|
|
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 / OpenOffice.org 3.4.1 en-US + langpacks, MS-Windows XP Home SP3
This forum is unusable, use instead Apache OpenOffice forums |
|
| Back to top |
|
 |
Programmierer Newbie

Joined: 15 Dec 2010 Posts: 2
|
Posted: Thu Dec 16, 2010 10:36 am Post subject: |
|
|
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 |
|
 |
B Marcelly Super User

Joined: 12 May 2004 Posts: 1414 Location: France
|
|
| Back to top |
|
 |
|