Results 1 to 3 of 3

Thread: Search a text file for a string

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Aug 1999
    Location
    Ont, Canada, Earth
    Posts
    458
    Hi,

    The text file contains several records in the same format (see below). Each record is 2 lines of data. I need to search the file for a specific record (eq. Record857 - see below). Once I find it, I need to read in 5th item from the NEXT line in the record (221 - see below).

    ------------------------------------------------
    Sample of the text file
    ------------------------------------------------
    Record055 455 331
    23 392 112 665 999 3563

    Record857 928 021
    66 947 446 535 221 0083

    Record726 664 222
    40 372 220 11 102 2223
    ------------------------------------------------

    Thanks
    Thanks

    Tomexx.

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Wink Hmmm

    First try using line input.
    Code:
    Dim X() as string
    Open "Filename" for input as #1
    Do while not EOF(1)
      Line INput#1, Temp$
        if left(temp$,9) = "Record857" then
               'You have located it
               'Do another line input to get the next line
              Line Input#1,Temp$
                X = Split(Temp$)
                'X(4) should contain your data
                exit sub ' found it....now exit sub
        end if
    loop
    Did this off the top of my head...hope it works
    (if someone notices error please correct!)

    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Talking Oops...

    Forgot:
    Code:
    Close#1
    after Loop


    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

Posting Permissions

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



Click Here to Expand Forum to Full Width