Solved

VBA: Read textfiles in Unix format

Posted on 2006-06-23
6
1,427 Views
Last Modified: 2012-05-05
I have a huge textfile in Unix format of several megabytes that I want to read line by line. How do I do this in VBA?
Do I have to convert it to DOS/Windows format first? How?
0
Comment
Question by:IgnaceLamine
  • 3
6 Comments
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 16967515
Hi,

The UNIX and DOS (and Windows) operating systems differ in the format in which they store text files.

DOS places both a carriage return character [vbCr or Chr$(13)] & a line feed character [vbLf or Chr$(10)] at the end of each line of a text file, but Unix uses only a line feed character.

Some DOS applications need to see carriage return characters at the ends of lines, and may treat Unix-format files as giant single lines.

Some Unix applications won't recognize the carriage returns added by DOS, and will display Ctrl-M characters at the end of each line (shown on-screen as ^M).


You do not have to convert UNIX text files to DOS format in order to read them, but you need to ensure that whilst reading the lines with VBA that you then replace all single vbLf characters with vbCrLf.

BFN,

fp.
0
 
LVL 35

Accepted Solution

by:
[ fanpages ] earned 125 total points
ID: 16967530
As example of VBA to read UNIX text files can be found here:

"Replace line-feeds with carriage return / line feed"
[ http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_10444356.html ]

There is also reference to a utility you can use instead called "unix2dos".

The link in the PAQ is now offline, but searching in Google can return many similar tools, such as:
[ http://www.nichesoftware.co.nz/unix2dos.html ]


BFN,

fp.


0
 
LVL 35

Expert Comment

by:[ fanpages ]
ID: 17309948
Thanks (again) Dan.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Best way to parse out a json string in VB6? 10 163
Adding to a VBA? 6 69
vb6 connector to mongodb 2 81
How to set the sa password in a vb6 code for sql connection 9 52
When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
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…
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…

776 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