?
Solved

read in a text file in line by line parse it and write to a new file to save as a CSV

Posted on 2003-03-05
3
Medium Priority
?
170 Views
Last Modified: 2011-10-03
I need to read in a text file one line at a time as I read it in I will parse it and then write it again to a new file to be saved as as CSV.

What would be the simplest way to do this??

0
Comment
Question by:Maritimer
[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 28

Expert Comment

by:AzraSound
ID: 8072997
Dim lngReadFileNum As Long
Dim lngWriteFileNum As Long
Dim strBuffer As String


lngReadFileNum = FreeFile
lngWriteFileNum = FreeFile

Open "C:\path\file.txt" For Input As #lngReadFileNum
Open "C:\path\newfile.csv" For Output As #lngWriteFileNum

    Do Until EOF(lngReadFileNum)
        Line Input #lngReadFileNum, strBuffer
        'parse data in strBuffer

        'write to new file
        Print #lngWriteFileNum, "Some New Data"
    Loop

Close #lngWriteFileNum
Close #lngReadFileNum
0
 

Author Comment

by:Maritimer
ID: 8073107
This may be a dumb question but I seem to be getting an error on the second line:

Open "C:\path\newfile.csv" For Output As #lngWriteFileNum

ERROR 54

File already open.
Any ideas???
0
 
LVL 28

Accepted Solution

by:
AzraSound earned 200 total points
ID: 8073132
You should be opening different files.  The first 'Open' statement should be opening the file you are reading data in from, and the second 'Open' should specify the new file to be written to.  These two files must be different.
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

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 have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
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 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…
Suggested Courses

777 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