The code still isn't working for the following test case:
Line1
Line2
Line5
Line6
Where line 3 and 4 are blank.
Main Topics
Browse All TopicsI have a text file that I read line by line into a variable. After doing some cleanup on the line I append it to the strFile variable.
What I would like to do is eliminate instances of two carriage returns in a row. I am getting some errors trying to work with LineFeed characters.
Here is my proposed code:
If strLine = VbCrLf and previous_line = VbCrLf Then
' don't append it
Else
strFile = strFile & strLine & VbCrLf
End If
However, the line breaks don't appear to be VbCrLf's. Any help?
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
Do Until fileCSV.AtEndOfStream
strLine = fileCSV.ReadLine & " "
strLine = GetNewLineValue(strLine)
If strLine = VbCrLf or strLine = vbCr or strLine = vbLf Then
Call DisplayContents("HERE!")
Select Case previous_line
Case vbCrLf
' don't append it
Case vbCr
' don't append it
Case vbLf
' don't append it
Case Else
strFile = strFile & strLine & VbCrLf
End Select
Else
strFile = strFile & strLine & vbCrLf
End If
previous_line = strLine
Loop
Goodness, you are correct. Forest for the trees issue. Here is the correct code:
Do Until fileCSV.AtEndOfStream
strLine = fileCSV.ReadLine & " "
strLine = GetNewLineValue(strLine)
If strLine = "" And previous_line = "" Then
' don't append it
Else
strFile = strFile & strLine & vbCrLf
End If
previous_line = strLine
Loop
Business Accounts
Answer for Membership
by: jwarnkenPosted on 2009-11-02 at 13:53:41ID: 25724179
vbCrLf, vbCr, and vbLf are all valid end of line settings
Select allOpen in new window