Page 1 of 1

Counting number of characters

Posted: Mon May 05, 2008 10:49 am
by Omar319
Hi, I'm trying to create a button that will count the number of characters, like a word count but a character count instead.

This is the code I have come up with but seems to come up with a random string of numbers:

Code: Select all

on mouseUp
  local tNumber, tNumOutput
  put field "Text" into tNumber
  repeat for each char theChar in tNumber
  put chartonum(theChar) after tNumOutput
end repeat
put tNumOutput into field "Count"
end mouseUp
Where've I gone wrong?

Thanks
Omar :)

Posted: Mon May 05, 2008 11:32 am
by Klaus
Hi Omar,

chartonum(the character) = the ASCII number of that character!

You need a simple

Code: Select all

on mouseup
  put the number of chars of fld "Text" into fld "Count"
end mouseup
That's it :-)


Best

Klaus

Posted: Mon May 05, 2008 11:38 am
by Omar319
Thanks Klaus

Perfect :D

Omar 8)

Posted: Mon May 05, 2008 12:23 pm
by BvG
there's another possibility:

Code: Select all

put the length of field "someField" into someVar

Posted: Mon May 05, 2008 12:48 pm
by Omar319
Hi,
That works too.

Thanks for the replies.

Omar 8)