Files

I need help with opening files, then searching for text and replacing the text.


Comments

  • : I need help with opening files, then searching for text and replacing the text.


    VB5 code, may not work without a few changes:


    Dim FileText As String 'Know this works

    Open MyFile For Binary As 1 'Know this works

    FileText = Space$(LOF(1)) 'Creates a string the same length as the file

    Get #1, , FileText 'Should work

    Close

    Do

    x = InStr(x + 1, FileText, OldText) 'Know this works

    If x 0 Then

    FileText = Left$(FileText, x - 1) & NewText & Right$(FileText, Len(FileText) - (x + Len(OldText) - 1)) 'Should work

    FileChanged = 1

    Else

    Exit Do

    End If

    Loop

    If FileChanged = 1 Then

    Open MyFile For OutPut As 1 'Know this works

    Close 'Know this works

    Open MyFile For Binary As 1 'Know this works

    Put #1, , FileText 'Should work

    Close

    End If


    Hope this helps!


Sign In or Register to comment.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories