PDA

Click to See Complete Forum and Search --> : String search using several files


Juerg E. Frey
Nov 11th, 1999, 02:22 PM
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

smalig
Nov 11th, 1999, 08:10 PM
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
smalig@hotmail.com
smalig.tripod.com (http://smalig.tripod.com)