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

x
?
Solved

Deleting header lines in text file

Posted on 2003-11-26
3
Medium Priority
?
393 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
[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
3 Comments
 
LVL 14

Assisted Solution

by:aelatik
aelatik earned 375 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 375 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

New benefit for Premium Members - Upgrade now!

Ready to get started with anonymous questions today? It's easy! Learn more.

Question has a verified solution.

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

Introduction While answering a recent question (http://www.experts-exchange.com/Q_27402310.html) in the VB classic zone, I wrote some VB code in the (Office) VBA environment, rather than fire up my older PC.  I didn't post completely correct code o…
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…
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…
Suggested Courses

721 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