Results 1 to 7 of 7
  1. #1
    Access-Deb
    Guest

    Searching Strings and Looping (Access97 and 2K)

    I would like to do a search through a text document, (dot.txt), and find examples of exact string matches if the match is prefixed by an exact string. Here's an example of what I'm trying to do:
    --------------
    Start: Here's a big cat
    Yak, Yak, Yak
    Blah, Blah, Blah
    --------------
    Start: Oh Yeah? (Here's a big cat)
    Mine is bigger
    More Yak, Yak
    --------------
    Start: Oh Yeah? (Here's a big cat)
    Oh no it's not
    More Blah, Blah
    --------------
    Even though the above 3 string sets are interspaced with any number of other non-matching string sets, I want all of the matching string sets to be returned as shown above. Here's the pseudo-code for what I'm trying to do:
    --------------
    Starting at the beginning of file
    Find the first occurrence of string "Start:"
    Ignore any blank spaces before the next string
    Remember everything before the next occurrence of a line break or carriage return
    Find every line that has this string preceded by "Start:" and any number of blank spaces
    List everything from first match to last match as shown in the above example
    Tag each line of any of the returned matches so as not to use them again for comparisons.

    Now start over and find the next occurrence of string "Start:" that isn't tagged.
    Ignore any blank spaces before the next string
    Remember everything before the next occurrence of a line break or carriage return
    Find every line that has this string preceded by "Start:" and any number of blank spaces
    List everything from first match to last match as shown in the above example
    Tag each line of any of the returned matches so as not to use them again for comparisons.
    Do until EOF or no more matches are found
    ---------------
    Sorry about the length of this post, but I had to get the entire concept through. I've never done any string comparison work, and I'm kinda lost here.

    Thank you for any help you can provide,

  2. #2
    Super Moderator jscher2000's Avatar
    Join Date
    Feb 2001
    Location
    Silicon Valley, USA
    Posts
    23,112
    Thanks
    5
    Thanked 93 Times in 89 Posts

    Re: Searching Strings and Looping (Access97 and 2K)

    VBA offers a very old school method for working with plain text files that would be a good fit for your needs if you only needed to read text out. However, the requirement to read iteratively and not snag the same line twice is tough because the methods I know allow reading or writing, but not both at the same time, at least not for unstructured text.

    The relevant commands are:

    Open c:dot.txt for Input as #1
    LineInput #1, strVariable

    You could write all the Start: lines that you don't use on the first pass to a second file.

    Open "c:dot2.txt" for Output As #2
    Print #2, strVariable

    And then repeat the process. However, since you have a potentially large number of passes through your file, this could generate quite a few files, and dealing with all the names could be a big hassle.

    Another way to handle this would be to use Word. Word is perfectly happy flipping back and forth within and between documents. However, since you are posting this on the Access board, perhaps that is not feasible or at least not sufficiently efficient? If you can use Word, you might want to cross-post to the VBA forum for more assistance.

  3. #3
    Access-Deb
    Guest

    Re: Searching Strings and Looping (Access97 and 2K)

    Thanks Jefferson, I'll file that method away for future use. However, the string blocks I'm using number in the tens of thousands. I'm trying to figure out a way to segregate the threads, (Similar to the way that the threads are for this forum, but based on string content instead of numerical relationships.

  4. #4
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Searching Strings and Looping (Access97 and 2K)

    Using ADO, you can use a Stream object to handle something like this. Look at KnowledgeBase article <A target="_blank" HREF=http://support.microsoft.com/support/kb/articles/q248/2/55.asp>Use ADO Records and Streams to Open a Document [Q248255]</A> for instructions.
    Charlotte

  5. #5
    hotbudare
    Guest

    Re: Searching Strings and Looping (Access97 and 2K)

    Hi Charlotte,
    Have u been able to use the code posted in the link you recommended?
    It looks like it's mean for VB only...
    I can't compile (at least) the following two lines (using A2K):

    Dim rec As ADODB.Record
    Dim stm As ADODB.Stream

    . <img src=/S/confused.gif border=0 alt=confused width=15 height=20>

  6. #6
    Plutonium Lounger
    Join Date
    Dec 2000
    Location
    Sacramento, California, USA
    Posts
    16,775
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Searching Strings and Looping (Access97 and 2K)

    Do you have the necessary references set? You have to have at least ADO 2.5 installed and referenced and you must have at least IE 5.0 on your computer to make it work. The default Access 2000 ADO library seems to be 2.1, and that won't work with the Stream object.

    The code isn't meant for VB only, although you have to tweak it for Access, since the text property of a textbox in Access can only be referenced while the control has the focus, and you don't update the text property, you update the value. Aside from that, it should work for you.
    Charlotte

  7. #7
    hotbudare
    Guest

    Re: Searching Strings and Looping (Access97 and 2K)

    Charlotte,
    You were right about the version I was using
    Thanks a lot for pointing that out. I'll repeat the testing tomorrow <img src=/S/doh.gif border=0 alt=doh width=15 height=15>
    I'll repeat the testings tomorrow ...

Posting Permissions

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