-1

I use this code in this page, for reading data line by line. Now how I can edit text file, line by line?

(VB6) Reading text files line by line looking for specific words

    If InStr(1, lines(i), "sample text", vbTextCompare) Then
    lines (i)= "new text"

I used this code, but nothing changed.

Community
  • 1
  • 1
Elias
  • 39
  • 1
  • 5

1 Answers1

0

I think, you are editing the string array but not the text file itself. You need to save that updated string array into the text file.

Dim i as Integer
Dim myFile as Integer
myFile = FreeFile
Open "C:\MyTextFileFromStringArray.txt" For Output As #myFile
For i = 0 To UBound(lines)
    Print #myFile, lines(i)
Next i
Close #myFile