Solved

Convert EOL character (UNIX to PC)

Posted on 2002-05-16
3
783 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Introduction I needed to skip over some file processing within a For...Next loop in some old production code and wished that VB (classic) had a statement that would drop down to the end of the current iteration, bypassing the statements that were c…
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…
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…
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…

914 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now