Solved

Convert EOL character (UNIX to PC)

Posted on 2002-05-16
3
787 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
[X]
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
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

I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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…

749 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