Reading a file from VBscript or visual basic 6.0

Hello, i need to deal with a text file from VBScript or visual basic 6.0 and in the process replace a word like blue for yellow, where can i find an example of it?
emontAsked:
Who is Participating?
 
Mike TomlinsonConnect With a Mentor Middle School Assistant TeacherCommented:
Here is a VB6 solution:

Option Explicit

Private Sub Command1_Click()
    replaceInFile "C:\someFile.txt", "blue", "yellow"
End Sub

Private Sub replaceInFile(ByVal fileName As String, ByVal oldString As String, ByVal newString As String)
    Dim ff As Integer
    Dim entireFile As String
   
    If Dir(fileName) <> "" Then
        ff = FreeFile
        Open fileName For Binary Access Read As #ff
        entireFile = Input(LOF(ff), ff)
        Close #ff
   
        entireFile = Replace(entireFile, oldString, newString)
   
        ff = FreeFile
        Open fileName For Binary Access Write As #ff
        Put #ff, , entireFile
        Close #ff
    Else
        MsgBox fileName, vbCritical, "File not found"
    End If
End Sub
0
All Courses

From novice to tech pro — start learning today.