?
Solved

Convert EOL character (UNIX to PC)

Posted on 2002-05-16
3
Medium Priority
?
795 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 400 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone 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 While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…
Suggested Courses

771 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