Find/Count problem solved

ncouch ncouch at mail.airmail.net
Sat Apr 12 20:37:01 EDT 2003


After playing around with some ideas here is what I came up with for my
problem.  My thanks to all for their help.



on mFind

  --setting things up
  put empty into field "Hits"
  select text of field "Results"
  set the textStyle of selectedText to "plain"

  put the number of lines of field "Results" into lCount
  put 0 into x
  global cVar,x

  --asking for input
  ask "What do you want me to find?"
  put it into cVar
  if cVar is empty then
    exit mFind
  end if

  --finding the first string
  -- and setting the initial mark
  find cVar in field "Results"
  put the foundChunk into temp1
  set the textStyle of the foundChunk to "box"
  add 1 to x

  --finding the string
  repeat until forever
    find cVar in field "Results"
    get the foundChunk

    --data checks
    if the foundChunk = temp1 then
      exit repeat
    end if
    if the foundChunk is empty then
      exit repeat
    end if

    add 1 to x
    set the textStyle of the foundChunk to "box"

  end repeat

  -- here is what I found
  put "Search string " & tab & tab & cVar into line 1 of field "Hits"
  put "# of hits " & tab & tab & tab & x into line 2 of field "Hits"
  put "Lines searched " & tab & lCount into line 3 of field "Hits"
  set the vScroll of field "Results" to 0
  set the hScroll of field "Results" to 0

end mFind



It works like a champ.

Nate




More information about the use-livecode mailing list