Solved

Convert EOL character (UNIX to PC)

Posted on 2002-05-16
3
784 Views
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).
0
Comment
Question by:loudinbk
  • 2
3 Comments
 
LVL 26

Accepted Solution

by:
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
0
 
LVL 22

Expert Comment

by:rspahitz
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.
0
 
LVL 22

Expert Comment

by:rspahitz
ID: 7017633
That print should end in a semicolon:

Print #ff, s;
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

828 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