Difficulty writing a real search box (Rev Studio)
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
Difficulty writing a real search box (Rev Studio)
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
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
Re: Difficulty writing a real search box (Rev Studio)
Hi Herb,
I am not sure if I understand you right...
Try this:
Please tell me if that helps.
Best
Klaus
P.S.
I will move this thread to the "LiveCode Beginner" forum now.
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
Best
Klaus
P.S.
I will move this thread to the "LiveCode Beginner" forum now.
Re: Difficulty writing a real search box (Rev Studio)
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
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
Re: Difficulty writing a real search box (Rev Studio)
Hi Herb,
maybe I did not correctly understand what you were after.
Remove the "find empty" line and try again.
Best
Klaus
maybe I did not correctly understand what you were after.
Remove the "find empty" line and try again.
Best
Klaus
Re: Difficulty writing a real search box (Rev Studio)
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:
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-
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
...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
Re: Difficulty writing a real search box (Rev Studio)
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
Re: Difficulty writing a real search box (Rev Studio)
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
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
Re: Difficulty writing a real search box (Rev Studio)
Hi Herb,
I tried this script in the field "find" and it works for the limited testing I have done:
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
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
Kind regards
Bernd