Hi,
Want to know how to delete a line in a file if i come across a blank line. I do not want to create a temp file doing this. I want to be able to perform any operation on the same file. Please help!!!!
Printable View
Hi,
Want to know how to delete a line in a file if i come across a blank line. I do not want to create a temp file doing this. I want to be able to perform any operation on the same file. Please help!!!!
Try this:
Good luck!Code:Public Sub RemoveBlankLines(FileName As String)
Dim iFile As Integer
Dim sLines() As String
Dim sTemp As String
Dim iCount As Integer
Dim i As Integer
ReDim sLines(0 To 100)
iFile = FreeFile
Open FileName For Input As #iFile
Do While Not EOF(iFile)
Line Input #iFile, sTemp
If Len(sTemp) > 0 Then
sLines(iCount) = sTemp
iCount = iCount + 1
If iCount > UBound(sLines) Then
ReDim Preserve sLines(0 To iCount + 100)
End If
End If
Loop
Close #iFile
Open FileName For Output As #iFile
For i = 0 To iCount
Print #iFile, sLines(i)
Next
End Sub