Delete all records in a text file except first line

Posted on 2004-11-29
Last Modified: 2010-05-02
From vb 6, how to delete all records in a txt file keeping only first line (column header or field names) intact.

Question by:Mike Eghtebas
    LVL 55

    Expert Comment

    by:Jaime Olivares
    Hi eghtebas,
    Have a look to this previous question:

    Good luck,
    LVL 7

    Accepted Solution

    why not read in the first line, delete the file and write to it newly?

    dim strBuf as string

    open "fil1.txt" for input as #1
    Line input #1, strBuf
    close #1
    Kill "fil1.txt"
    open "fil1.txt" for output as #1
    Print #1, strBuf
    close #1
    LVL 33

    Author Comment

    by:Mike Eghtebas
    Hi  _agj_,

    Your solution is more suitble to use in my application.  I am testing it now.

    Hi Jaime,

    Thank you for the link.  I don't have complication (requiring the file has to exist and can't be deleted, etc.).  


    LVL 28

    Assisted Solution

    Just a note,you don't need to kill the file in agj's example because when you open it for output the file will be overwritten.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    I’ve seen a number of people looking for examples of how to access web services from VB6.  I’ve been using a test harness I built in VB6 (using many resources I found online) that I use for small projects to work out how to communicate with web serv…
    Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
    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…

    728 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

    16 Experts available now in Live!

    Get 1:1 Help Now