• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 123
  • Last Modified:

VB files

please write two functions that add\remove a line from file
the line is selected in a list box, and the function search this line in the text file and add\remove it.
1 Solution
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
    Close iFile1, iFile2
    Kill sFilePath
    FileCopy "c:\temp123z.ajd", sFilePath
    Kill "c:\temp123z.ajd"
End Function

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

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now