Difficulty writing a real search box (Rev Studio)

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
herbwords
Posts: 70
Joined: Sat Dec 01, 2007 2:59 am

Difficulty writing a real search box (Rev Studio)

Post by herbwords » Wed Jan 26, 2011 1:37 am

Hello,

I'm trying to create Text Search field that I type a word into and push return that finds the whole word in a scrolling field on the same card.
I copied the example in the Revolution Resource Center for the Text Search entry field:

on returnInField -- goes in Find field's script
if me is empty then beep -- nothing to find
else find whole me -- "me" is the field
end returnInField

I set the Find command ignores

It does some what ok searching in order from top of list to bottom except it hilites one line in blue and puts the found box around the word I'm looking for sometimes.
If I try to find an entry I've already passed it just beeps till I hit the return key a second time.

Any one have a solution to correct these behaviors?

Thanks

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Difficulty writing a real search box (Rev Studio)

Post by Klaus » Wed Jan 26, 2011 1:00 pm

Hi Herb,

I am not sure if I understand you right...

Try this:

Code: Select all

on returninfield  
   ## First remove the first found string
   ## Means: let the engine forget the last find :-)
   find EMPTY

   put me into tFind
   if tFind is empty then 
       beep
  else 

     ## If you do NOT specify a target field, the engine will search everything on 
     ## the current card and will probabvly fiond nothing else! 
     ## Thats why you need to hit RETURN a second time!
     find whole tFind in fld "Your filed to be searched here"
  end if
end returnInField
Please tell me if that helps.


Best

Klaus

P.S.
I will move this thread to the "LiveCode Beginner" forum now.

herbwords
Posts: 70
Joined: Sat Dec 01, 2007 2:59 am

Re: Difficulty writing a real search box (Rev Studio)

Post by herbwords » Wed Jan 26, 2011 7:49 pm

Hi Klaus,

Thanks. That works better. But, it won't find the same word in another place in the field. When I hit return the second time it doesn't do anything. Even if I retype the word it won't find the next occurrence?

herbwords

Klaus
Posts: 14193
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Re: Difficulty writing a real search box (Rev Studio)

Post by Klaus » Wed Jan 26, 2011 7:54 pm

Hi Herb,

maybe I did not correctly understand what you were after.
Remove the "find empty" line and try again.


Best

Klaus

doc
Posts: 148
Joined: Fri Jun 09, 2006 4:30 pm

Re: Difficulty writing a real search box (Rev Studio)

Post by doc » Wed Jan 26, 2011 8:46 pm

Herb,
I've attached a tiny little sample stack that seems to do what you want...
I simply grabbed some headlines and pasted them into a scrolling field, then added this code in the search field:

Code: Select all

on returnInField
   put fld "SearchTerm" into tSearch
   find string tSearch in fld "DataSource"
end returnInField
On pressing the enter key, it will find each subsequent instance of teh keyword you search for.

...if my attachment fails for some reason, you can grab it here:
http://www.docstoolchest.com/catch_all/SimpleSearch.rev

Hope that helps,
-Doc-
Attachments
SimpleSearch.zip
(1.83 KiB) Downloaded 356 times

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10317
Joined: Wed May 06, 2009 2:28 pm

Re: Difficulty writing a real search box (Rev Studio)

Post by dunbarx » Wed Jan 26, 2011 10:23 pm

This script puts a box around every instance of the word when you type a return:

Code: Select all

on returninField
   -- the text to find is called tSearch
   put the textstyle of word 1 to the number of words of me of me into tStyle
   if tStyle <> "mixed" then set the wordsToSkip of me to 0
   put the  wordsToSkip of me into index
   get wordoffset(tSearch,me,the wordsToSkip of me)
   set the wordsToSkip of me to it
   if tStyle <> "mixed" then  select word it of me else select word (index + the wordsToSkip of me) of me
   set the textStyle of the selection to "box"
end returninField

herbwords
Posts: 70
Joined: Sat Dec 01, 2007 2:59 am

Re: Difficulty writing a real search box (Rev Studio)

Post by herbwords » Wed Feb 02, 2011 10:12 pm

Hi Klaus,

Thanks so much for your help. I'm still having problems. I have a Scrolling List Field and it acts different then a scrolling field when I search it so I had to add (set the listBehavior of fld "herbs" to false) and (set the hilitedLine of field "herbs" to 0) not sure if this is proper but it seems to work.
The problem is: The herbs field has 3 different types of ginseng in it. So if I use (find EMPTY) in the script to clear the last search I can't use return to keep searching. If I don't use (find EMPTY) in the script, and I change the search to another herb after I find ginseng a second time, then return answers "herbName was not found"
So I need to find all occurrences with the returnInField but if I change the search I need to find the new herb.
Also, you might note the card script "doReset"
I've attached herbSearch stack with my info in it.

Do this: Type in ginseng, press Return, type in yarrow press Return
now if you change the Find field script and add "find EMPTY" it will only find ginseng one time

Thanks again,

herb
Attachments
herbSearch.zip
(8.71 KiB) Downloaded 346 times

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4171
Joined: Sun Jan 07, 2007 9:12 pm

Re: Difficulty writing a real search box (Rev Studio)

Post by bn » Thu Feb 03, 2011 12:23 am

Hi Herb,

I tried this script in the field "find" and it works for the limited testing I have done:

Code: Select all

local sLastSearch = ""
on returninfield
   set the listBehavior of fld "herbs" to false
   set the hilitedLine of field "herbs" to 0
   --find EMPTY
   put field "Find" into tSearch
   if tSearch is empty then 
      beep
   else 
      if tSearch = sLastSearch then
         find whole tSearch in fld "herbs"
      else
         find empty
         find whole tSearch in fld "herbs"
         put tSearch into sLastSearch
      end if
      if the foundChunk is empty then
         beep
         answer "“" & tSearch & "” was not found."
      end if
   end if
end returnInField
I checks whether the search is different from the previous search and resets the search accordingly. It uses a script local variable sLastSearch which is persistent between runs.

Kind regards

Bernd

Post Reply