Line offset of an item (and other similar functions).

Alex Tweedly alex at tweedly.net
Tue Jan 25 09:14:13 EST 2005


Raymond E. Griffith wrote:

>
>Hmmm. Come to think of it, there should also be a "lineoffset" function.
>
> put lineoffset(pItem,pData) into ptestline
>
>No need for a "repeat for each line" construct, although you'd need to turn
>wholeMatches to false.  If you are concerned with making sure that you get
>an entire item and not a part of it, then you could do a test on it, as,
>
> repeat while ptestline > 0
>   if pItem is an item of line ptestline of pData then
>     return ptestline
>   else
>     put lineoffset(pItem,pData,ptestline) into ptestline
>   end if
> end repeat
>  
>
Yes, I tried that approach.
The full code fragment isn't quite that straightforward (need to add the 
offset each time round the loop):
  put lineOffset(pID, pData) into tLineCount
  repeat while tLineCount > 0
    if pID is among the items of line tLineCount of pData then
      exit repeat
    else
      put lineoffset(pID,pData,tLineCount) into t
      if t = 0 then
        put 0 into tLineCount
        exit repeat
      end if
      add t to tLineCount
    end if
  end repeat

and it also works. But this too is much less obvious, and long enough 
that it would need to be put into a separate function anyway.
It's on the list of alternatives to be benchmarked if performance is a 
problem.

Thanks
-- Alex.




-- 
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 265.7.3 - Release Date: 24/01/2005



More information about the use-livecode mailing list