Solved

VB

Posted on 1998-12-30
2
144 Views
Last Modified: 2010-05-03
2 functions that add\remove a line from a text file
0
Comment
Question by:amird
2 Comments
 
LVL 18

Accepted Solution

by:
deighton earned 10 total points
ID: 1453252
Private Function AddLine(sFilePath As String, sLine_to_add As String)

    Dim iFile1 As Integer
   
    iFile1 = FreeFile
    Open sFilePath For Append As #iFile1
   
    Print #iFile1, sLine_to_add
   
    Close iFile1
   
   
End Function

Private Function RemoveLine(sFilePath As String, sLine_to_delete As String)

    Dim iFile1 As Integer
    Dim iFile2 As Integer
   
    Dim sTemp As String
   
    iFile1 = FreeFile
    Open sFilePath For Input As #iFile1
   
    iFile2 = FreeFile
    Open "c:\temp123z.ajd" For Output As #iFile2
   
    While Not EOF(iFile1)
   
        Line Input #iFile1, sTemp
       
        If sTemp <> sLine_to_delete Then
       
            Print #iFile2, sTemp
           
        End If
       
    Wend
   
    Close iFile1, iFile2
   
    Kill sFilePath
    FileCopy "c:\temp123z.ajd", sFilePath
    Kill "c:\temp123z.ajd"
   
End Function

0
 
LVL 7

Expert Comment

by:linda101698
ID: 1453253
deighton has proposed an answer to your question. Does it solve your problem?  If not, you need to post an explanation as to why it did not solve the problem.

Linda Gardner
Customer Service @ Experts Exchange
0

Featured Post

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

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…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…

706 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

18 Experts available now in Live!

Get 1:1 Help Now