Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Blank Line at end of Txt File

Status
Not open for further replies.

Lbob

Programmer
May 23, 2003
157
GB
I'm creating a text file from excel which works fine, but there's a blank line at the bottom of it, which I can't get rid of. Can any one help me?
Here's my code
sFilename = Range("FileLocation") & Format(Now), "ddmmyyhhmm")
Open sFilename & ".txt" For Output As #1
iRow = C_ROWSTART
For i = 1 To nRows
If IsEmpty(Cells(iRow, 1)) Then
Print #1, "8=abc4.2" & _
",17=" & Cells(iRow, 11) & _
",20=0" & _
",1=111123" & _
",48=" & Cells(iRow, 12) & _
",22=4" & _
",54=" & Cells(iRow, 2) & _
",32=" & Cells(iRow, 3) & _
",31=" & Cells(iRow, 4) & _
",15=22" & _
",75=" & Format(Cells(iRow, 10), "yyyymmdd") & _
",64=" & Format(Cells(iRow, 6), "yyyymmdd") & _
",60=" & Format(Cells(iRow, 5), "hhmmss") & _
",109=" & Cells(iRow, 8) & _
",142=1111"
End If
iRow = iRow + 1
Next
Close #1

cheers
lbob
 
The first thing I wonder about is where nRows gets its value - and whether that value could be zero-based instead of 1-based.

You might try for i = 1 to nRows-1 and see what you get. (If that works, I'd be tempted to try for i = 0 to....)


Good luck.
 
There shouldn't be an empty line, given your code. Where do you find the empty line? Is it there when you read back the file in VBA, using line input?


Rob
[flowerface]
 
The empty line appears at the end. If you open the file in notepad you can definitley see a new line has been created.
 
I don't know how to stop it but I can tell you why it's happening -
Code:
Print #
adds a line feed at the end of each line.

N.
 
Yes, each line is terminated by a CR/LF. You could avoid that by adding a semicolon to the last print# statement. But the CR/LF/EOF combination is the most common end to a text file. For example, if you use line input# to read back your file, you'll see that there is no empty line - as soon as your last real line is read, eof(#) will be TRUE.
So I guess my question is - why is the CR/LF a problem?


Rob
[flowerface]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top