What line is it?
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller
What line is it?
I have a list field with two items per line..
17 18
22 19
13 21
27 26
I can find the line which item 2 matches
e.g 21 but I then need the line number so that I
can extract item 1 for that line and 3 or 4
lines before and after.
17 18
22 19
13 21
27 26
I can find the line which item 2 matches
e.g 21 but I then need the line number so that I
can extract item 1 for that line and 3 or 4
lines before and after.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
-
- Posts: 253
- Joined: Wed Aug 19, 2015 4:29 pm
Re: What line is it?
Here's what I came up with.
Code: Select all
local tSearch
ask "Number to find?"
put it into tSearch
set the itemdelimiter to space
repeat with x = 1 to the number of lines in fld "Your Field"
if (item 2 of line x of fld "Your Field" = tSearch) then
answer (tSearch && "is in line" && x &"."&cr&"Item 1 of line"&&x&&" is" && item 1 of line x of fld "Your Field")
end if
end repeat
Re: What line is it?
Thanks for your help ClipArtGuy.
I must remember to use the field and
not the array which populates it (and
is superfluous anyway).
I must remember to use the field and
not the array which populates it (and
is superfluous anyway).
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
Programming powered by coffee.
-
- VIP Livecode Opensource Backer
- Posts: 7228
- Joined: Sat Apr 08, 2006 8:31 pm
- Location: Minneapolis MN
- Contact:
Re: What line is it?
The lineOffset function might be easier, but keep in mind that it will return only the first instance it finds unless you add the second "skip" parameter. Since you want the second item, search for space and the number.
That will give you the line number, which you can use to extract word 2, and then add 1 sequentially to get the next 2 lines.
Code: Select all
put lineOffset(space & tNum, fld x) into tLine
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
HyperActive Software | http://www.hyperactivesw.com
-
- VIP Livecode Opensource Backer
- Posts: 9645
- Joined: Wed May 06, 2009 2:28 pm
- Location: New York, NY
Re: What line is it?
What everyone said.
And especially Jacque's comment about the first instance. You ought to write a general purpose handler that extracts all the foundLines in any given search, as well as foundChunk within each. I have been using one forever, and find it an invaluable general purpose gadget that I call from a library stack.
Anyone remember Rinaldi's "fullFind"?
Craig
And especially Jacque's comment about the first instance. You ought to write a general purpose handler that extracts all the foundLines in any given search, as well as foundChunk within each. I have been using one forever, and find it an invaluable general purpose gadget that I call from a library stack.
Anyone remember Rinaldi's "fullFind"?
Craig
-
- Posts: 720
- Joined: Thu Sep 11, 2014 1:49 pm
- Location: The Netherlands