Results 1 to 2 of 2

Thread: String search using several files

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 1999
    Location
    Switzerland
    Posts
    1

    Post

    I am not a VBgeek yet need a small VB6 program. It should read a short word from one file and search text in a second file for how many times the word occurrs. The word and the number of occurrences should then be written in a third file. The basis is DNA and so only 4 letters occur.
    File 1 contains 10'000 "words", i.e., 10 - 30 letter "words", each in a single row.
    And here comes the problem:
    File 2 contains 4.5 MILLION letters (a genome) with no gaps (spaces) between them.
    File 3 would then contain the result of the search.
    If anyone could come up with an elegant solution to this I would be MEGAthankful.
    Cheers - Juerg

  2. #2
    Addicted Member
    Join Date
    Oct 1999
    Posts
    232

    Post

    Try it:

    ------------------
    Private Sub WordSearch(Word$)

    Dim Line$, x%, p&, Count&

    Open "d:\2.txt" For Input As #2

    While Not EOF(2)
    Line Input #2, Line
    p = 1
    Do
    x = InStr(p, Line, Word)
    If x > 0 Then Count = Count + 1
    p = x + Len(Word)
    Loop Until x = 0
    Wend

    Close #2

    Open "d:\3.txt" For Append As #3
    Print #3, Word & " " & Count
    Close #3

    End Sub

    Private Sub Start()

    Dim Word$

    Open "d:\1.txt" For Input As #1

    While Not EOF(1)
    Line Input #1, Word
    WordSearch (Word)
    Wend

    End Sub

    ------------------
    smalig
    [email protected]
    smalig.tripod.com

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