search a field

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller

Post Reply
Preston Shea
Posts: 73
Joined: Sat Apr 08, 2006 6:51 pm

search a field

Post by Preston Shea » Mon Mar 28, 2011 4:49 pm

I want to look for a word in a tab itemdel field and if found return the line the word was found in. I am using

repeat with i = 1 to the number of lines in fld fA
set the cursor to busy
if item 1 of line i of fld fA = lookFor then
????????????????????????????????
exit repeat
end if
end repeat

Is this the best way to approach the problem?

What do I put in ???????????????????????????????? to retrieve the line in fld fA in which lookFor is item 1 ?

Also: How would I scroll fld fA to the line in which lookFor is item 1 ?
In nova fert animus mutatas dicere formas corpora.

Dixie
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 1336
Joined: Sun Jul 12, 2009 10:53 am

Re: search a field

Post by Dixie » Mon Mar 28, 2011 6:17 pm

Preston...

Not knowing exactly what you want to do but something like this might get you pointed in the right direction

Code: Select all

on mouseUp
   put whatever into theWordToFind
   put lineOffset(theWordToFind,fld 1) into theLine
   set the scroll of fld 1 to (theLine * the textheight of fld 1)
end mouseUp
or maybe this if it is item 1 of the line you are after

Code: Select all

 on mouseUp
       put whatever into theWordToFind
       put lineOffset(theWordToFind,item 1 of fld 1) into theLine
       set the scroll of fld 1 to (theLine * the textheight of fld 1)
       put theLine
    end mouseUp
Make sure that there is a text size in 'text formatting' in the property inspector of the fld... else it doesn't work.

be well

Dixie

Preston Shea
Posts: 73
Joined: Sat Apr 08, 2006 6:51 pm

Re: search a field

Post by Preston Shea » Mon Mar 28, 2011 8:05 pm

Dixie,

Many, many thanks!

Preston
In nova fert animus mutatas dicere formas corpora.

bn
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 4163
Joined: Sun Jan 07, 2007 9:12 pm

Re: search a field

Post by bn » Tue Mar 29, 2011 10:58 pm

Hi,

@ Dixie

here is a way to set the scrolling that I like very much for wrapped lines. For fields that have their dontWrap property set to false. The line number will not always be useful in that case. In case you don't know this I guess you might like it too.

Code: Select all

on mouseUp
   put field "What" into theWordToFind
   
   put lineOffset(theWordToFind,fld 1) into theLine -- do whatever with the line number
   
   -- find the scroll
   put offset (theWordToFind, field 1) into tChar
   set the vscroll of field 1 to (the formattedHeight of char 1 to tChar of field 1) - the effective textHeight of field 1
end mouseUp
if you want to be more precise with scrolling you could fiddle with the borderwidth and the margins but this should meet most needs of scrolling text into view.

Kind regards

Bernd

Post Reply