Solved

Changing data in a Tab Delimited text files

Posted on 2004-08-01
2
335 Views
Last Modified: 2010-05-02
I have a tab delimited text file that contains 26 fields and anywhere from 1 upwards rows.

The rows can contain information in all 26 fields or only the first field.

The sixth field is currently empty (Class).   If the first column contains TRNS or SPL I need to put information into the sixth field and copy this to a new tab delimited text file (or update the original).

I have been able to read the test file into a recordset, however this recordset will not allow me to update field (5).   I have also writen script to write from the first recordset toa new tab delimited file.   Can some one tell me how when writing to the new file, I will be able to add information to field 5 of the recordset if the above requirements are met.  

Regards

brendon Gardiner  
0
Comment
Question by:BrendonG
[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
2 Comments
 
LVL 14

Expert Comment

by:aelatik
ID: 11687493
Here you go,

Private Sub Form_Load()

    Const FILENAME As String = "c:\temp.csv" ' the file to read
    Const NEWFILENAME As String = "c:\temp1.csv" ' the newfile to create
   
    Dim FNUM As Integer
    Dim FNUM1 As Integer
    Dim TEMP As String
    Dim FIELDS() As String
    Dim I As Long
    Dim NEWLINE As String
   
        FNUM = FreeFile
        FNUM1 = FreeFile
        Open FILENAME For Input As #1
        Open NEWFILENAME For Output As #2
       
            While Not EOF(1)
                Line Input #1, TEMP
                FIELDS = Split(TEMP, vbTab)
                If FIELDS(0) = "TRNS" Or FIELDS(0) = "SPL" Then ' check for criteria
                    FIELDS(5) = "TheNewValue" ' set the new value
                End If
                NEWLINE = ""
               ' construct the new line
                For I = 0 To UBound(FIELDS)
                    NEWLINE = NEWLINE & FIELDS(I)
                    If UBound(FIELDS) <> I Then NEWLINE = NEWLINE & vbTab
                Next
                Print #2, NEWLINE
            Wend
        Close #1
        Close #2
End Sub
0
 
LVL 14

Accepted Solution

by:
aelatik earned 500 total points
ID: 11687496
Clear the unneccesary declarations on this one :

Private Sub Form_Load()

    Const FILENAME As String = "c:\temp.csv"
    Const NEWFILENAME As String = "c:\temp1.csv"
   
    Dim TEMP As String
    Dim FIELDS() As String
    Dim I As Long
    Dim NEWLINE As String
   
        Open FILENAME For Input As #1
        Open NEWFILENAME For Output As #2
       
            While Not EOF(1)
                Line Input #1, TEMP
                FIELDS = Split(TEMP, vbTab)
                If FIELDS(0) = "TRNS" Or FIELDS(0) = "SPL" Then FIELDS(5) = "TheNewValue"
                NEWLINE = ""
                For I = 0 To UBound(FIELDS)
                    NEWLINE = NEWLINE & FIELDS(I)
                    If UBound(FIELDS) <> I Then NEWLINE = NEWLINE & vbTab
                Next
                Print #2, NEWLINE
            Wend
        Close #1
        Close #2
End Sub
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
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…
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…

739 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