how to get to the top of a table field

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: heatherlaine, Klaus, FourthWorld, robinmiller, kevinmiller

Post Reply
THOLIEN
Posts: 11
Joined: Mon Jul 02, 2018 6:03 pm

how to get to the top of a table field

Post by THOLIEN » Wed Jul 11, 2018 7:22 pm

This should be a very simple thing to do but ...
I have a small table field on a card that contains 10 rows and 11 columns.
My script finds a line in the table and uses the information from the line to calculate a bunch of stuff.
The next time I run the script the find does not find the thing that I knowe is in the table.
In the API dictionary I found this little tidbit:
"The find command starts searching after the previously-found text (if there was a previous find command)"
I want to start from the top of the list every time I use the find command.
What is the best way of doing that?

Klaus
Posts: 10381
Joined: Sat Apr 08, 2006 8:41 am
Location: Germany
Contact:

Re: how to get to the top of a table field

Post by Klaus » Wed Jul 11, 2018 7:25 pm

Hi THOLIEN,

do not use FIND but lineoffset() or something!
What did you script so far?


Best

Klaus

THOLIEN
Posts: 11
Joined: Mon Jul 02, 2018 6:03 pm

Re: how to get to the top of a table field

Post by THOLIEN » Wed Jul 11, 2018 7:56 pm

It's too bad the find command gets no love.

FIND was there before I started on this script.
After a few trials and errors lineOffset looks like it is going to work.

Thanks.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5569
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: how to get to the top of a table field

Post by dunbarx » Wed Jul 11, 2018 9:04 pm

Hi.

"Find" is a little odd in that, if after a successful find the little block is drawn around the foundText, and you try to find something again, it will often (not always) simply erase that box and stare at you.

Here is a little demo. Make a button near your table field. Put this in its script:

Code: Select all

on mouseUp
   find string any char of "abcdfsert" in fld "yourTableField"
   wait 10
   find ""
end mouseUp
Assuming those chars live somewhere in your table field, hit the button a few times. Always works. But this begs the issue above.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5569
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: how to get to the top of a table field

Post by dunbarx » Wed Jul 11, 2018 11:15 pm

Do not dismiss "find" just yet.

Invariably, one collects information about a successful find immediately, using the foundChunk, foundLine or foundWhatever. In that way, it is not important that the "foundBox" might foul up successive manual find operations. In other words, if any of the above functions are used for whatever purpose, it is perfectly reasonable and straightforward to, say:

Code: Select all

on mouseUp
   repeat 10
   find string any char of "abcdfsert" in fld "xx"
   put the foundChunk & return after temp
   --processAway
   find ""
end repeat
answer temp
end mouseUp
This happens in an instant, and all is well.

Craig

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5569
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: how to get to the top of a table field

Post by dunbarx » Wed Jul 11, 2018 11:41 pm

It appears I have not used "Find" in quite a while, though I used to.

After a little testing, each instance of a string is found during successive manual finds, but once the last one is found, the next attempt will fail. If one tries after that, the whole thing starts over, working just fine, until the inevitable failure.

It is almost as if a "find empty" took place, which resets the find sequence.

I don't see where it says either that "Find" does not start over from the beginning after finding the last instance, or that it just doesn't work for one time if it has already found that last instance.

Is it worth a report to QCC?

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4658
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: how to get to the top of a table field

Post by jacque » Thu Jul 12, 2018 5:20 pm

It's not a bug, it's by design. If you check the result you'll see that the find command reports "not found" after the last successful search. That's how you know you've found every instance. Then it resets.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5569
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: how to get to the top of a table field

Post by dunbarx » Thu Jul 12, 2018 6:00 pm

OK.

So this is different than if one finds successive text on different cards in a stack, where LC (and HC before it) will cycle back to the start after text was found on the lastmost card, ad infinitum.

Craig

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4658
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: how to get to the top of a table field

Post by jacque » Thu Jul 12, 2018 6:34 pm

In LC the final result should be the same "not found", regardless of the navigation.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5569
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: how to get to the top of a table field

Post by dunbarx » Thu Jul 12, 2018 6:47 pm

Jacque.

It never happens. The process goes back to the beginning and continues...

It works differently than finding text limited to a designated field.

Craig

THOLIEN
Posts: 11
Joined: Mon Jul 02, 2018 6:03 pm

Re: how to get to the top of a table field

Post by THOLIEN » Thu Jul 12, 2018 8:52 pm

I'm totally fine with the way it works, but I would like to be able to start searching from the top of the list if I want to. I was deceived and glad I found this before I released the product to users.

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4658
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: how to get to the top of a table field

Post by jacque » Thu Jul 12, 2018 9:58 pm

It never happens. The process goes back to the beginning and continues...

It works differently than finding text limited to a designated field.
So it does. I don't think it always did that.
I would like to be able to start searching from the top of the list
For that case, use this:

Code: Select all

find empty
find <whatever>
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5569
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: how to get to the top of a table field

Post by dunbarx » Thu Jul 12, 2018 10:31 pm

Tholien.

What Jacque said, and if you look through the thread, you will see why. Remember what you read in the dictionary. "Find Empty" resets the find "queue". Once that happens, all subsequent finds start from the beginning.

Craig

Post Reply

Return to “Getting Started with LiveCode - Experienced Developers”