PDA

View Full Version : text search program and counter


John-
10-06-2003, 09:06 PM
i was wondering if i wanted to make a program
which would search through a text file to see how many times a certain word appears for example the word is hello and this program searched a textfile for this word and then in a caption or textbox tells you how many times that word appears how would i go about doing this.
but say i wanted it to count the word regardless of caps sensitiveness.

baloney_mahoney
10-07-2003, 01:09 AM
Dim Data As String
Dim word_to_find As String
Dim q1, q2, counter As Integer

Open TextFile_Path For Input As #1
Line Input #1,Data
Close #1


q1=1

counter=0

word_to_find = "Hello"

Do While True

q2=Instr(q1,Data, LCase(word_to_find))

If q2 = 0 Then Exit Do

counter=counter + 1
q1 = q2 + 1

Loop

Labe1.Caption = "The word '" & word_to_find & "' occured " & counter & " times."

baloney_mahoney
10-07-2003, 01:33 AM
Correction to above


In above code snippit change:

q2=Instr(q1,Data, LCase(word_to_find))

to:

q2=Instr(q1,Data, word_to_find, vbTextCompare)