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!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
bonbon
- Posts: 62
- Joined: Thu Jul 17, 2008 11:48 pm
Post
by bonbon » Thu Oct 23, 2008 5:58 pm
I've set up a separate substack as a floating "Find" dialog, but my code seems to be resetting to the beginning of the field to be searched.
Example code for the "Find" button:
Code: Select all
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 ?
-
gyroscope
- Livecode Opensource Backer

- Posts: 404
- Joined: Tue Jan 08, 2008 3:44 pm
-
Contact:
Post
by gyroscope » Thu Oct 23, 2008 6:46 pm
Hi bonbon
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.
So, in the main stack script:
Code: Select all
global gFindText
on openStack
put "" into gFindText
end openStack
and in your Find subStack button:
Code: Select all
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.
Hope that helps!

-
bonbon
- Posts: 62
- Joined: Thu Jul 17, 2008 11:48 pm
Post
by bonbon » Thu Oct 23, 2008 10:18 pm
Thanks for the tips - I'm still struggling to get it to do what I want, but you've pointed me in the right direction.
-
gyroscope
- Livecode Opensource Backer

- Posts: 404
- Joined: Tue Jan 08, 2008 3:44 pm
-
Contact:
Post
by gyroscope » Thu Oct 23, 2008 10:27 pm
I made a small stack; would that be of help? I could post in Rev Online if you like.

-
kotikoti
- Posts: 72
- Joined: Tue Apr 15, 2008 7:35 pm
Post
by kotikoti » Thu Oct 23, 2008 10:35 pm
gyroscope
Please do...
Build 160
Version 2.9.0
Platform: Windows
-
gyroscope
- Livecode Opensource Backer

- Posts: 404
- Joined: Tue Jan 08, 2008 3:44 pm
-
Contact:
Post
by gyroscope » Thu Oct 23, 2008 10:47 pm
OK, all done.... called "DG Find stack.rev" in Rev Online, under gyroscope.

-
bonbon
- Posts: 62
- Joined: Thu Jul 17, 2008 11:48 pm
Post
by bonbon » Sat Oct 25, 2008 2:59 pm
Thanks for your help Gyroscope - much appreciated. This is where I am still getting stuck:
In the main form, when the "Search" button is pressed, gSelField is set to:
In the floating "Find" substack, "answer gSelField" shows that this comes out as "field 4".
So, in the "Find" substack, if I code:
Code: Select all
find string gFindText in field 4 of stack gWhoCalledFind
it works, but if I code:
Code: Select all
find string gFindText in gSelField of stack gWhoCalledFind
it doesn't work (error message: "Chunk: source is not a container").
The reason for wanting to do this is to allow the option of searching by field. I'm trying to build a "find" script which I can use from any stack.
I'm sure it's easy when you know how ... any help would be very welcome !
-
bn
- VIP Livecode Opensource Backer

- Posts: 4172
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Sun Oct 26, 2008 12:32 am
Hi bonbon,
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
-
bonbon
- Posts: 62
- Joined: Thu Jul 17, 2008 11:48 pm
Post
by bonbon » Sun Oct 26, 2008 10:53 am
Hi 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
(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).
All the best,
Bonbon
-
Mark
- Livecode Opensource Backer

- Posts: 5150
- Joined: Thu Feb 23, 2006 9:24 pm
-
Contact:
Post
by Mark » Sun Oct 26, 2008 11:43 am
Bonbon,
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
-
bonbon
- Posts: 62
- Joined: Thu Jul 17, 2008 11:48 pm
Post
by bonbon » Sun Oct 26, 2008 1:14 pm
Mark,
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
Code: Select all
find gFindText in field "Field" on card 1 of stack "Main"
, I'm looking for something along the lines of
Code: Select all
find gFindText in field <last field with focus in stack "Main"> on card 1 of stack "Main"
(if this makes sense).
All the best,
Bonbon
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Sun Oct 26, 2008 3:34 pm
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
Code: Select all
put the name of the selectedField into gSelField
In the button on the find stack, change the line where the search field is hard coded to
Code: Select all
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).
-
bonbon
- Posts: 62
- Joined: Thu Jul 17, 2008 11:48 pm
Post
by bonbon » Sun Oct 26, 2008 4:23 pm
That's it ! Exactly what I was after.
Huge thanks to everyone for helping. Now to take over the world (or at least finish my "Find" dialog).
All the best
Bonbon
-
SparkOut
- Posts: 2947
- Joined: Sun Sep 23, 2007 4:58 pm
Post
by SparkOut » Wed Oct 29, 2008 11:35 am
Just another thought:
Code: Select all
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
Code: Select all
find tFindText in ((gSelField) && "on card <cardname or number> of stack" && quote & "stackname" & quote)
-
bonbon
- Posts: 62
- Joined: Thu Jul 17, 2008 11:48 pm
Post
by bonbon » Wed Oct 29, 2008 1:17 pm
Wow ... better and better !
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 !