Convert EOL character (UNIX to PC)

Posted on 2002-05-16
Last Modified: 2008-02-01
What is the easiest way to convert every EOL character in a ascii file.  I need to convert from a Line Feed (Unix Style) to a Carriage Return + Line Feed (PC Style).
Question by:loudinbk
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
LVL 26

Accepted Solution

EDDYKT earned 100 total points
ID: 7015013
Public Sub ConvertDelimiter(ByVal fileName As String)
    Dim I As Long, ff As Integer, s As String
    On Error Resume Next
    ff = FreeFile
    Open fileName For Binary As #ff
    s = Space$(LOF(ff))
    Get #ff, , s
    Close ff
    s = Replace(s, vbLf, vbCrLf)
    ff = FreeFile
    Open fileName For Output As #ff
    Print #ff, s
    Close ff
End Sub
LVL 22

Expert Comment

ID: 7015164
A non-VB solution is to load the file into Wordpad then save.  It will tell you that you're about to lose the formatting, which will convert the LFs into CRLFs.

Obviously this is not ideal if you'll be doing this on many files or on a regular basis.

Also, the way I prefer in EDDYKT's code is to replace the Get with Input:

   Open fileName For Binary As #ff
   s = input$(lof(ff), #ff)
   Close ff

Same result.

Also, the line:

       Print #ff, s

should be

   Print #ff, s

to prevent a new CRLF from appearing at the end of the document.
LVL 22

Expert Comment

ID: 7017633
That print should end in a semicolon:

Print #ff, s;

Featured Post

Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…

690 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question