Results 1 to 3 of 3
  1. #1
    Join Date
    Aug 2003

    Unanswered: Adding/Editing text in notepad

    Can anyone help please?

    I have a text file with HTML in it. From Access, i would like to open the notepad, find the string

    <TD><INPUT size=40 name=line1></TD></TR>

    and replace it with

    <TD><INPUT size=40 value="6" name=line1></TD></TR>

    So far i have:

    Open "FILENAME" For Input As #1
    Line Input #1, myLine
    For i = 1 To Len(myLine)
    If Mid(myLine, i, 18) = "<TD><INPUT size=40" Then

    End If
    Next i
    Close #1

    Can anyone help with the replace/ insert bits?



  2. #2
    Join Date
    Dec 2003
    Toronto, Ont. Canada

    Re: Adding/Editing text in notepad

    Try this procedure...

    1) You only opened a file for Input (reading the records)
    You need to be able to Output the text after it's changed... so what I'd do is write to a new file... then deal with deleting the old one and renaming the new one later...

    2) I'd use the InStr() function... This one will give the the position of the first occurence of the search string in the record... If there is no match then it'll return 0

    3) You would have had a problem with the quote characters in your replace string... so I concatenated the ASCII character code for " into the string... (as you'll see below)

    Option Compare Database
    Option Explicit

    Sub ReplaceData()
    Dim strRecord As String, strNewRecord As String
    Dim strSearch As String, strReplace As String
    Dim intPos As Integer

    strSearch = "<TD><INPUT size=40"
    strReplace = "<TD><INPUT size=40 value=" & Chr(34) & "6" & Chr(34) & " name=line1></TD></TR>"

    'open file to write to
    Open "NewFileName" For Output As #2 Len = 152

    'open file, iterate through records, writing each to file
    Open "OldFileName" For Input As #1

    Line Input #1, strRecord
    Do While Not EOF(1)
    intPos = InStr(1, strRecord, strSearch, 1)
    If intPos > 0 Then
    strNewRecord = Left(strRecord, intPos - 1) & strReplace & _
    Right(strRecord, Len(strRecord) - (intPos + Len(strSearch)))
    Print #2, strNewRecord
    Print #2, strRecord
    End If
    Line Input #1, strRecord

    Close #1
    Close #2
    MsgBox "File complete!"

    End Sub

    I haven't tested it, but it compiles okay... The good thing is that you won't be changing the original file so you can test it for a bit... see what results you get... and when you're sure it's okay, add code to delete the old file and rename the new one... (If that's needed...)


  3. #3
    Join Date
    Dec 2003
    Toronto, Ont. Canada

    Re: Adding/Editing text in notepad

    P.S. You mentioned using Notepad but your code didn't show that... (and I couldn't figure out why you'd want to open Notepad since it can all be done programmatically...) so I didn't include any code for that purpose...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts