Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Changing data in a Tab Delimited text files

Posted on 2004-08-01
2
Medium Priority
?
354 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 2000 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

Independent Software Vendors: 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

Enums (shorthand for ‘enumerations’) are not often used by programmers but they can be quite valuable when they are.  What are they? An Enum is just a type of variable like a string or an Integer, but in this case one that you create that contains…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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

715 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