Counting number of characters

Got a LiveCode personal license? Are you a beginner, hobbyist or educator that's new to LiveCode? This forum is the place to go for help getting started. Welcome!

Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller

Post Reply
Omar319
Posts: 14
Joined: Sun Apr 27, 2008 10:57 am

Counting number of characters

Post by Omar319 » Mon May 05, 2008 10:49 am

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 :)

Klaus
Posts: 14177
Joined: Sat Apr 08, 2006 8:41 am
Contact:

Post by Klaus » Mon May 05, 2008 11:32 am

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

Omar319
Posts: 14
Joined: Sun Apr 27, 2008 10:57 am

Post by Omar319 » Mon May 05, 2008 11:38 am

Thanks Klaus

Perfect :D

Omar 8)

BvG
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 1239
Joined: Sat Apr 08, 2006 1:10 pm
Contact:

Post by BvG » Mon May 05, 2008 12:23 pm

there's another possibility:

Code: Select all

put the length of field "someField" into someVar
Various teststacks and stuff:
http://bjoernke.com

Chat with other RunRev developers:
chat.freenode.net:6666 #livecode

Omar319
Posts: 14
Joined: Sun Apr 27, 2008 10:57 am

Post by Omar319 » Mon May 05, 2008 12:48 pm

Hi,
That works too.

Thanks for the replies.

Omar 8)

Post Reply