CodeItBetter Programming Another VB Programming Blog

How to delete a line for a given line number from a text file

Posted on January 5, 2009
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
'Text File Handling - How to delete a line for a given line number from a text file
Private Function DeleteLine(ByVal sFile As String, ByVal lLine As Long) As Boolean
    Dim sLines() As String, FF As Integer, n As Long
    If Len(Dir(sFile)) = 0 Or lLine < 1 Then Exit Function
 
    FF = FreeFile
    Open sFile For Input As #FF
    sLines = Split(Input(LOF(FF), #FF), vbCrLf)
    Close #FF
 
    If UBound(sLines) < lLine - 1 Then Exit Function
 
    Open sFile For Output As #FF
    For n = 0 To UBound(sLines)
        If Not n = lLine - 1 Then Print #FF, sLines(n)
    Next n
    Close #FF
    DeleteLine = True
End Function
Comments (0) Trackbacks (0)

No comments yet.


Leave a comment


 

No trackbacks yet.