VBcoders Guest



Don't have an account yet? Register
 


Forgot Password?



Replace a single line of a file. For example replace one line of a .cfg or a .ini, in order to alte

by MacLeod Broad (1 Submission)
Category: Files/File Controls/Input/Output
Compatability: VB 6.0
Difficulty: Unknown Difficulty
Originally Published: Tue 15th January 2008
Date Added: Mon 8th February 2021
Rating: (1 Votes)

Replace a single line of a file. For example replace one line of a .cfg or a .ini, in order to alter program settings or outside variables,

Rate Replace a single line of a file. For example replace one line of a .cfg or a .ini, in order to alte



Dim Str As String
Dim newFileContent As String
Dim i As Integer

lineNumber = lineNumber - 1
i = 1

    Open filePath For Input As #1
        Input #1, Str
        newFileContent = Str
        Do While Not EOF(1)
            If i = lineNumber Then
                Input #1, Str
             Str = replacementText
              newFileContent = newFileContent + vbNewLine + Str
        Else:
                Input #1, Str
                newFileContent = newFileContent + vbNewLine + Str
        End If
        i = i + 1
        Loop
    Close #1
    If i < lineNumber Then Error (32202)
    Open filePath For Output As #1
        Print #1, newFileContent
    Close #1
End Function


Download this snippet    Add to My Saved Code

Replace a single line of a file. For example replace one line of a .cfg or a .ini, in order to alte Comments

No comments have been posted about Replace a single line of a file. For example replace one line of a .cfg or a .ini, in order to alte. Why not be the first to post a comment about Replace a single line of a file. For example replace one line of a .cfg or a .ini, in order to alte.

Post your comment

Subject:
Message:
0/1000 characters