|
Hello all,
I trying to search a text file using a boolean AND search. What i want to happen is when a user types in type values to search e.g. Name Department (Taylor marketing) i want it to only read out the lines which contain both values.
At present it reads out all lines with Taylor in and all lines with marketing. The code i have so far is:
arrKeywords = Split(strSearchField, " ")
iUBound = UBound(arrKeywords)
While Not objTextStream.AtEndOfStream
objLine = objTextStream.ReadLine
For iLoop = 0 to iUbound
if instr(1,objLine,uCase(arrKeywords(iLoop)),1) Then
printLine(objLine)
End if
Next
WEnd
Any help on how i could fix this would be much appreciated.
|
|
|
Assuming your posted code works, just modify the loop to set a variable indicating if one of the words is NOT found. After the loop, if that variable is not false, then print the line.
allTermsFound = True
For iLoop = 0 to iUbound
if not instr(1,objLine,uCase(arrKeywords(iLoop)),1) Then
allTermsFound = False
End if
Next
if allTermsFound then printLine(objLine)
|
|
|
|
|
|
|
Cooler King, don't forget to follow up here in the forum with your solution. That's what forums are all about-- getting answers, and letting others learn from your journey!
Thanks for using codetoad.com forums! :)
|
|
|
|
|
Trust me know one wants to go on the journey that i had :-)
He's what i eventually finished up with:
arrKeywords = Split(strSearchField, " ")
iUBound = UBound(arrKeywords)
icount = True
while not objTextStream.AtEndOfStream
objLine = objTextStream.ReadLine
bFound = true
For iLoop = 0 to iUbound
if instr(1,objLine," " & uCase(arrKeywords(iLoop)) & " ",1) = 0 Then
bFound = False
Exit For
End if
Next
if bFound then
icount = False
printLine(objLine)
End if
wend
Hope it helps anyone who needs it.
|
|
|
|
|
|
|
|