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

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

What line is it?

Post by RossG » Sun May 20, 2018 12:35 am

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-one and counting.
Programming powered by coffee and nicotine.

ClipArtGuy
Posts: 220
Joined: Wed Aug 19, 2015 4:29 pm

Re: What line is it?

Post by ClipArtGuy » Sun May 20, 2018 1:18 am

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

Re: What line is it?

Post by RossG » Sun May 20, 2018 2:56 am

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-one and counting.
Programming powered by coffee and nicotine.

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

Re: What line is it?

Post by jacque » Sun May 20, 2018 6:45 pm

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: 6160
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: What line is it?

Post by dunbarx » Mon May 21, 2018 9:28 pm

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: 401
Joined: Thu Sep 11, 2014 1:49 pm
Location: The Netherlands

Re: What line is it?

Post by mrcoollion » Tue May 22, 2018 7:02 am

This thread might be of interest ?

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

Post Reply

Return to “Getting Started with LiveCode - Complete Beginners”