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,
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
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.