Solved

Deleting header lines in text file

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
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…

757 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now