Solved

Deleting header lines in text file

Posted on 2003-11-26
3
387 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

VMware Disaster Recovery and Data Protection

In this expert guide, you’ll learn about the components of a Modern Data Center. You will use cases for the value-added capabilities of Veeam®, including combining backup and replication for VMware disaster recovery and using replication for data center migration.

Question has a verified solution.

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

Suggested Solutions

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
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…

803 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