which item contains the foundText?

Jan Schenkel janschenkel at yahoo.com
Mon Sep 20 02:31:19 EDT 2004

--- Rich Lague <laguer at ucs.orst.edu> wrote:
> I’m making an application that keeps it’s data in a
> text file and I’m 
> trying build in a find field. So, I set up a script
> for the field:
> on returnInField
>    global tVar  -- contains the text file
>    global itemNum -- a handler in the stack script
> uses this to display 
> the current record
>    if me is empty then beep -- nothing to find
>    find the text of me in tVar
> -- now I need to get the item number that the text
> was found in.
> -- the script below does not work. I also tried “is
> within”--also 
> doesn’t work.
>    set the itemDelimiter to "|"
>    repeat with i = 1 to the number of items in tVar
>      if i contains the foundText then
>        put i into itemNum
>        exit repeat
>      end if
>    end repeat
>   put itemNum
> goRecord
> end returnInField
> So...How do I determine which item my foundText is
> in?
> Thanks!
> Rich Lague

Hi Rich,

First an important bit of information : 'find' only
works on fields in a stack, not a variable.
But you can use offset, lineOffset, wordOffset and
itemOffset to find data inside variables.

In the above case, I'd use itemOffset.
on returnInField
  global tVar
  global itemNum
  put the tet of me into theStringToFind
  set the itemDelimiter to "|"
  put itemOffset(theStringToFind,tVar) into itemNum
  put itemNum
end returnInField

Allow me to encourage you to use a clear naming scheme
for variables, as this will help you track errors and
read your own scripts more quickly.
One guideline that I know a number of Revolutionaries
follow is the Scripting Style Guide :

Hope this helped,

Jan Schenkel.

"As we grow older, we grow both wiser and more foolish at the same time."  (La Rochefoucauld)

Do you Yahoo!?
Yahoo! Mail Address AutoComplete - You start. We finish.

More information about the use-livecode mailing list