CodeItBetter Programming Another VB Programming Blog

How to Insert a line of text in a file

Posted on January 4, 2009
1
2
3
4
5
6
7
8
9
10
11
12
'Text File Handling - How to Insert a line of text in a file
Private Sub insertLine(ByVal strFile As String, ByVal lineNumber As Long, _
    ByVal strLineOfText As String)
    Dim strBuff() As String: strBuff = Split(returnContents(strFile), vbCrLf)
    Dim i As Long
    Open strFile For Output As #1
    For i = 0 To UBound(strBuff)
        If i = lineNumber Then Print #1, strLineOfText
        Print #1, strBuff(i)
    Next
    Close #1
End Sub
Comments (1) Trackbacks (0)
  1. Thanks
    But I found a bug that returncontents as sub is not defined.
    Please rectify.


Leave a comment


 

No trackbacks yet.