Solved

Deleting header lines in text file

Posted on 2003-11-26
3
388 Views
Last Modified: 2012-05-04
I am writing data to an appending text file.  However, each batch file that is written has a header line(these are all the same).  The first header line is fine, but I don't not want any more subsequent headers after that.  Here is the code I have now, but for some reason it is not deleting any of my header lines...  Any suggestions or other possible solutions?

Header= <COLUMNS>|OFFICE_ID|TERMINAL_ID|OFFICE_NAME|PHONE....>

Code:
Open "c:\officeOutput.txt" For Append As #2
       
 'delete extra header lines
 For i = 0 To UBound(lines)
    str = lines(i)
    If InStr(str, "COLUMNS") > 0 Then
        lines(i) = vbNullChar
    End If
Next

 'uses filter to delete lines
lines = Filter(lines, vbNullChar, False)

 'write data
For j = 1 To UBound(lines)
      Print #2, getField(j,1) + getField(j,2)+getField(j,3)....
Next

Close#2
0
Comment
Question by:jennifere
3 Comments
 
LVL 14

Assisted Solution

by:aelatik
aelatik earned 125 total points
ID: 9825135
I made a function that does the job,

Function DeleteLineContaining(Filename As String, LineID As String)
    Dim BUFFER As New Collection
    Dim MYLINE As Variant
    Open Filename For Input As #1
        While Not EOF(1)
            Line Input #1, MYLINE
            BUFFER.Add MYLINE
        Wend
    Close #1
    Open Filename For Output As #1
        For Each MYLINE In BUFFER
            If InStr(1, MYLINE, LineID, vbTextCompare) = 0 Then
                Print #1, MYLINE
            End If
        Next
    Close #1
End Function

Private Sub Form_Load()
    Call DeleteLineContaining("c:\officeOutput.txt", "COLUMNS")
End Sub
0
 
LVL 10

Accepted Solution

by:
ADSaunders earned 125 total points
ID: 9825153
Hi jennifere,
I'm not sure what you are trying to achieve here, nor where the data is coming from to be appended to the file.
From your code it seems that some procedure is creating an array of lines which you then wish to append to the output file. If I am reading correctly, you don't wish to append any header lines. (-where are they coming from ??)
In any case, I would simlify to the following:

Open "c:\officeOutput.txt" For Append As #2
For j = 1 To UBound(lines)
    If InStr(lines(j), "COLUMNS") = 0 Then
      Print #2, getField(j,1) + getField(j,2)+getField(j,3)....
    end if
Next
Close#2

Regards .. Alan
0
 

Author Comment

by:jennifere
ID: 9825311
Okay, never mind.  I figured out the problem on my own.  I was writing my data to a collection and then trying to delete lines.  Anyhow, with a little bit of code rearrangement, it is working now.  I will go ahead and split the points because you both responded so quickly.  I appreciate it!  =)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

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…
There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
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…

838 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