LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
go to stack "Main" -- to set the focus onto the target stack
put the text of field "SearchFor" on card "Find" of stack "Find" into tFindText
find string tFindText in the selectedField
This finds the first occurrence, but when you press "Find" again, it keeps on finding the first occurrence, rather than moving on through the text. Possibly something to do with the "go to stack" command, but I can't spot how to get around this. Please could someone help ?
possibly something to do with the "go to stack" command, but I can't spot how to get around this.
You don't have to set the focus of the stack as such, that is implied in the find command. Also, your local variable "tFindText" needs to be a global variable.
global gFindText
on mouseUp pMouseBtnNo
put field "SearchFor" into gFindText
find gFindText in field "Field" on card 1 of stack "Main"
end mouseUp
This way, whatever you input into field "SearchFor", the first occurrence will be found, and subsequence mouse presses will move through the text, as you want.
what probably happens is that the selected field loses focus and then no field is selected -> error
set gSelField to "the name of the selected field" in the button, "the name of the selected field" gives you "field "xyz""
That way you give your find stack a destination to work on.
At least that is what I think is happening, may be not.
cheers
bernd
Thanks for the suggestion. I have just tried that, but I got the same situation. If I put in a temporary "answer" line, it shows that gSelField is now set to
field "Description"
(for example), which is what I want, but when I try to run the find command using gSelField, it crashes with "Chunk: source is not a container".
(Though I much prefer your idea of using "the name of" - much easier to follow.)
I think I need some way of turning gSelField into what is called a pointer in other languages (not sure on this, and not sure what to look up in the doc - pointers are different beasts in Rev).
Why don't you just take Gyroscope's stack and start from that? It worked fine when I tested it.
Keep in mind that showing an answer dialog causes currently focused fields to lose focus.
The selectedField is the field containing the search string rather than the field containing the text being searched. So, this can't work.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode
I think we're at cross purposes here. Gyroscope's stack does indeed work, but it assumes that you are always going to want to search the field "Field 1" (this is hard-coded). I'm trying to get to the point where the user can click in any field, then click on a search button to bring up a search dialog, and then the code behind the search dialog does a "find" in whatever field (in the Main stack) last had focus.
So, using Gyroscope's code as a starting point, rather than
On gyroscope's test stack make a new field. Call the first one FieldA and the new one FieldB (or whatever).
In the button on the main stack add a global variable and set it
find tFindText in field (gSelField) on card 1 of stack "Untitled 1" --or whatever stack name, etc
In other words, you had everything you needed already, but you need to enclose the variable name in parentheses to force the engine to parse the contents rather than treating the variable name as the object.
(I revised gyro's stack and reposted it in my user space for you to try).
put the long name of the selectedField into gSelField
will mean you can select any field on any card on any stack and have the search performed on the right field without having to code the destination card and stack as well as the field, as in
Note that the long name includes the descriptor "field" so it won't work if you say find tFindText in field (gSelField) with using the long name.
Bizarrely, although the (short) "name" will include the descriptor "field" as well, if you leave out the word "field" before the parentheses then it will fail - it's actually parsing find tFindText in field "field FieldName" on card blah..
It seems like the engine has been given a little "fudge" to cater for this, because with the short name it saves having to type the "proper" code
My first couple of weeks getting started with RunRev (in my spare time) were a bit of a struggle, but now I find that the more I use it, the more I like it.
As always, there have been a few sticking points, but with help from the forum (and getting used to where to look), they have all been sorted out much quicker than with other languages I have tried. Good stuff !