Results 1 to 5 of 5

Thread: Open text file and delete lines.

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #1
    VBAX Regular
    Joined
    May 2007
    Posts
    86
    Location

    Open text file and delete lines.

    I'm looking for a bit of code to open text files and delete about four or five different types of lines.

    These are trail files for ProE and I want to get rid of mouse movements automatically and comments that aren't needed:

    e.g. Comments:
    !%CIDatum planes will be displayed.
    (always start with a '!')

    e.g. Zooms:
    ~ Wheel `main_dlg_cur` `proe_win` \
    9 809 831 458752 0 1529 947 1920 1200 107781
    ('~ Wheel' starts two lines)

    I've tried similar to the replace command:


    [vba]
    Sub filemoder()
    Dim VFF As Long, trailwpath As String, trailoutput As String, trailbody As String, trailbodyO As String, vIStep As String
    trailwpath = "C:\Path\trailfile.txt"
    trailoutput = "C:\Path\trailfile2.txt"

    VFF = FreeFile
    Open trailwpath For Binary As #VFF
    trailbody = Space$(LOF(VFF))
    Get #VFF, , trailbody
    Close #VFF
    trailbodyO = Replace(trailbody, "!", "")
    Open trailoutput For Output As #VFF
    Print #VFF, trailbodyO
    Close #VFF

    End Sub


    [/vba]

    But with poor results. Mainly because it just takes out the "!" comment denoter. So the file then falls over

    I was thinking maybe read the file line by line and then only write to next file string if it didn't read the "!" or the "~ wheel", but I don't know how to do that.

    Any ideas?

    -AS
    Last edited by andysuth; 08-15-2007 at 05:49 AM.

Posting Permissions

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