Deleting a line from a text file?

I have three text files each containing information.  I am passing a string to a function which loops through the files.  If the string exists in the file, I want to delete it.

This is the code I have:

for x = 1 to 3
     Open strTextFileName(x) For Input As #x
     Do While Not EOF(x)
        ReDim Preserve strLines(NumLines)
        Line Input #x, strLines(NumLines)
        NumLines = NumLines + 1
     Close #x
     Open strTextFileName(x) For Output As #x
     For i = 0 To UBound(strLines)
      If UCase(Trim(strLines(i))) = UCase(Trim & _          (strDelete)) Then
      MsgBox strLines(i) & " is the same as " & strDelete
            Write #x, strLines(i)
      End If
     Close #x

However, this doesn't delete the line.

Any help on how i could do this would be greatly appreciated.

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

No you do not delete the line in text file.
You may be create new text file. Read each line from source file and then write in new file if the line may stay in new file.


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
CbelAuthor Commented:
This works!

For x = 1 To 3
        Open strTextFileName(x) For Input As #1
        Do While Not EOF(1)
            ReDim Preserve strLines(NumLines)
            Input #1, strLines(NumLines)
            NumLines = NumLines + 1
        Close #1
        Kill strTextFileName(x)
        Open strTextFileName(x) For Append As #1
        For i = LBound(strLines) To UBound(strLines)
           If strLines(i) <> strDelete Then
              Write #1, strLines(i)
        End If
        Close #1
        ReDim strLines(NumLines)
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic Classic

From novice to tech pro — start learning today.

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.