use-revolution Digest, Vol 14, Issue 54

Cubist at aol.com Cubist at aol.com
Mon Nov 22 02:04:41 EST 2004


In a message dated 11/21/04 1:55:20 PM, 
use-revolution-request at lists.runrev.com writes:

>
>Message: 6
>Date: Sun, 21 Nov 2004 13:33:56 -0600
>From: "Salinas, Ruben (GE Healthcare)" <Ruben.Salinas at med.ge.com>
>Subject: Basic field word count question
>To: <use-revolution at lists.runrev.com>
>Message-ID:
>   <45A5295FFA1CBE4D9BF44E8534D2686CFB3ABA at MKEMLVEM07.e2k.ad.ge.com>
>Content-Type: text/plain;  charset="iso-8859-1"
>
>My apologies for the simplicity of the question, but I'm just starting
>out with RunRev. Question is, how should I create a field on a card that
>displays the word count on a second field where the user is writing text?
>I would like the first field (word count) to recalculate automatically
>every time field 2 content changes. 
   My first answer to this question hasn't already been posted to the list, 
so here goes:

local TymeDelay = 250
on WordKount
  put the number of words in field "User Input" into field "Word Count"
  send "WordKount" to me in TymeDelay milliseconds
end WordKount

   This will update the wordcount field in realtime, automatically, four 
times a second. If that isn't fast enough, reduce the value of TymeDelay; if you 
don't want/need quarter-second accuracy, increase the value of TymeDelay.

   It's worth noting that the "number of words in [whatever]" function has a 
quirk in it: If you've got quoted strings (like, say, dialogue in a story), 
each such quoted string will count as 1 (one) word, *regardless* of how many 
spaces are in that quoted string. Thus, Rev thinks that the the string

I have a nice doggie

   (note the *absence* of quote marks) has 5 words in it, but Rev thinks the 
string

"I have a nice doggie"

   (note the *presence* of quote marks) is only *1* word. If your data is 
such that this could be a problem, you will be glad to know that there's a way to 
get the *real* wordcount, *including* what's within quotemarks: Use "the 
value of", which will, in effect, strip away the bleeding quote marks so's Rev can 
get at the *real* wordcount. Like so:

local TymeDelay = 250
on WordKount2
  put field "User Input" into Fred
  put 0 into WordKount
  repeat for each word WW in Fred
    add the number of words in (the value of WW) to WordKount
  end repeat
  put WordKount into field "Word Count"
  send "WordKount" to me in TymeDelay milliseconds
end WordKount2

   Hope this helps...


More information about the Use-livecode mailing list