Reputation: 29084
I have read this post: Read/Parse text file line by line in VBA. This post tells you how to read a line from a text file. However, I need to read a line and check whether it contains a number and if it does, I need to delete the line and save the text file.
While Not EOF(FileNum)
Line Input #FileNum, DataLine
If FindValue(DataLine) Then
'Stuck here.
End If
Wend
End Sub
Function FindValue(ByVal DataLine As Variant) As Boolean
For Index = 0 To NoOfLiquidatedDeals - 1
pos = InStr(DataLine, NoOfLiquidatedDealsArray(Index))
If pos > 0 Then
FindValue = True
End If
Next
End Function
I can read the line and check whether it contains a number. But I am not sure how to delete the line and save the text file. Need some guidance on this.
Upvotes: 1
Views: 12389
Reputation: 13690
You'll need to re-write the file, In other words:
input.txt
for Inputoutput.txt
for Outputoutput.txt
input.txt
output.txt
to input.txt
And in code:
Open "input.txt" For Input as #1
Open "output.txt" For Output as #2
While Not EOF(#1)
Input #1, DataLine
If Not FindValue(DataLine) Then
Print #2,DataLine
End If
Wend
Close #2
Close #1
Kill "input.txt"
Name "output.txt" As "input.txt"
Upvotes: 8