codetoad.com
  ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  Text file Boolean AND search problem  Cooler King at 14:30 on Tuesday, March 09, 2004
 

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.

  Re: Text file Boolean AND search problem  Troy Wolf at 18:12 on Tuesday, March 09, 2004
 

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)
Troy Wolf: site expert
Shiny Solutions


  Re: Text file Boolean AND search problem  Troy Wolf at 14:09 on Wednesday, March 17, 2004
 

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! :)
Troy Wolf: site expert
Shiny Solutions


  Re: Text file Boolean AND search problem  Cooler King at 14:15 on Wednesday, March 17, 2004
 

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.








CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums








Recent Forum Threads
•  Re: Print and print preview file on the website without using the File - Print on the IE
•  Re: ASP.NET web controls
•  Re: JavaSript Problem In Mac Safari Browser
•  Re: DHTML div positionning Problem
•  Convert script to NS6 compatible - Please Help!
•  Print .doc file from the website using System.Diagnostics.Process
•  Re: Fullscreen code
•  Re: iframe targeting
•  Excel n ASP


Recent Articles
Communicating with the Database (Using ADO)
MagicGrid
Simple Thumbnail Browsing Solution
Type Anywhere
A Better Moustrap: FmtDate to replace FormatDateTime
ASP.NET Forum Source Code
Internal Search Engine
Javascript Growing Window
Simple date validation
Search engine friendly URLs using ASP.NET (C#.NET)


Site Survey
Help us serve you better. Take a five minute survey. Click here!

© Copyright codetoad.com 2001-2005