?
Solved

deleting lines in a text file

Posted on 2003-03-28
1
Medium Priority
?
161 Views
Last Modified: 2010-04-07
how to delete for example the first 5 lines in a text file?
0
Comment
Question by:apitshah
[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
1 Comment
 
LVL 1

Accepted Solution

by:
robertlees earned 80 total points
ID: 8228989
You are going to have to copy the lines you want to a new file, kill the original file, then rename the new file.

For example, to delete the first 5 lines from c:\MyFile.txt

Call DeleteLines("c:\MyFile.txt", 5)

Sub DeleteLines(ByVal strFile As String, ByVal intLines As Integer)
    Dim strRecord As String
   
    Open strFile For Input As #1
    Open strFile & ".new" For Output As #1
    Do Until EOF(1)
        Line Input #1, strRecord
        intLines = intLines - 1
        If intLines <= 0 Then
            Print #2, strRecord
        End If
    Loop
    Close #1
    Close #2
    Kill strFile
    Name strFile & ".new" As strFile
End Sub
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
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…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
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…
Suggested Courses

743 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