Hi, normally I'm using the code below to search for words in a text file and display the entire line when a match has been found.
How can I do the same thing when I have the words (horse and fish) stored in an array? Normally I can replace "Horse" with strArray(0) and "Fish" with strArray(1), but the number of words in the array is always different.VB Code:
Private Sub Command1_Click() Dim sLines As String Open "C:\textfile.txt" For Input As #1 Do While Not EOF(1) Line Input #1, sLines If InStr(1, sLines, "horse") And InStr(1, sLines, "fish") Then Text1.Text = Text1.Text & sLines & vbCrLf End If DoEvents Loop Close #1 End Sub
In other words, how do I use an array with "If InStr(1, sLines, ????????) Then" when the amount of search words is always different?
(btw, the text file can be 50MB big)




Reply With Quote