Deleting a line from a text file?
Posted on 2003-02-24
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
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)
However, this doesn't delete the line.
Any help on how i could do this would be greatly appreciated.