I'm stumped on my find/count routine

Björnke von Gierke bvg at mac.com
Sat Apr 12 05:43:07 EDT 2003


I did not test your search, but it is there are some things you could 
check into to make your script work. (see below)


On Samstag, Apr 12, 2003, at 01:56 Europe/Zurich, nc wrote:

> I am working on a stack to query against atext fileand then display 
> the results in a field within the card using the "filter" command.
> 
> Now I am working on a script to count a string of text within the 
> filtered field. Here is the script:
> 
> ==============================================================
> 
> on mouseup
> 
>  --setting things up 
>  put empty into field "Hits"
>  put the number of lines of field "Results" into lCount
>  put 0 into x
additional needed for clearing your search to not start searching where 
the last one stopped:
find empty
> 
>  -- asking for input
>  ask "What do you want me to count?"
>  put it into cVar
> 
>  -- exitting the script upon Cancel
>  if cVar is empty then
>  exit mouseUp
>  else
> 
>  -- finding the first instance and
>  -- setting a marker using foundLine
>  find cVar in field "Results"
>  put the foundLine into y
>  add 1 to x
it is possible that cVar is not on the first line,
thus x =1 does not match the number of lines already gone by
> 
>  -- countingthe other instances
why do you first search for one instance, and then for the rest?
wouldn't it be easier to just search each line without verifying a 
first occurrence?
>  repeat until x = lCount
>  find cVar in field "Results"
>  if the foundLine = y then
>  exit repeat
you sure this shouldn't be "next repeat" ?
also the search starts where it last left of, so foundLine should not 
be able to equal y
>  else add 1 to x
>  end repeat
> 
>  end if
> 
>  -- here's what I found
>  put "Search string = " & cVar into line 1 of field "Hits"
>  if x=1 then
>  put "# of hits = " & x into line 2 of field "Hits"
>  else put "# of hits = " & (x-1) into line 2 of field "Hits"
>  put "# of lines searched = " & the number of lines of field 
> "Results" into line 3 of field "Hits"
>
> end mouseup
> ==============================================================
> ...

maybe it is one of these things that gives you strange results?



More information about the use-livecode mailing list