What line is it?

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

What line is it?

Post by RossG »

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.
Is age an excuse? Eighty-four and counting.
Programming powered by coffee.
ClipArtGuy
Posts: 268
Joined: Wed Aug 19, 2015 4:29 pm

Re: What line is it?

Post by ClipArtGuy »

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
RossG
Posts: 247
Joined: Thu Jan 08, 2015 7:38 am

Re: What line is it?

Post by RossG »

Thanks for your help ClipArtGuy.

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.
jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7423
Joined: Sat Apr 08, 2006 8:31 pm
Contact:

Re: What line is it?

Post by jacque »

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.

Code: Select all

put lineOffset(space & tNum, fld x) into tLine 
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.
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com
dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 10504
Joined: Wed May 06, 2009 2:28 pm

Re: What line is it?

Post by dunbarx »

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
mrcoollion
Posts: 744
Joined: Thu Sep 11, 2014 1:49 pm

Re: What line is it?

Post by mrcoollion »

This thread might be of interest ?

http://forums.livecode.com/viewtopic.php?t=14622
Post Reply