I'm stumped on my find/count routine

nc ncouch at mail.airmail.net
Fri Apr 11 20:00:01 EDT 2003


I am working on a stack to query against a text file and 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

  -- 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
  
    -- counting the other instances
    repeat until x = lCount
      find cVar in field "Results"
      if the foundLine = y then
        exit repeat
      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

==============================================================

Now for the problem.  What I am seeing is that when I execute this script and enter a string of text sometimes the script only counts 1 item when I see there are over half a dozen instances of the string.  Yes I have found this is a case sensitive search.  Most of the instances are contained in a single record and often involve SMTP addresses.  Are there some characters which the "find" command does not work with.  I didn't find anything in the doco to validate this, but I am beginning to suspect this to be true.

I have tried various combinations of the 'find' command including it with the 'whole', 'chars', and 'string' modifiers, but nothing seems to help.  The funny thing is sometimes this works just like it is supposed to.  Other times it can't find more than 1 instance of the string.

This is driving me batty.

Any ideas on what I have missed here.

TIA

Nate
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.runrev.com/pipermail/use-livecode/attachments/20030411/6f54bd64/attachment.html>


More information about the use-livecode mailing list