LiveCode is the premier environment for creating multi-platform solutions for all major operating systems - Windows, Mac OS X, Linux, the Web, Server environments and Mobile platforms. Brand new to LiveCode? Welcome!
put the number of lines of me into tCount
put 0 into tMinus
repeat with x=1 to the number of lines in fld "Group 1"
if line x of fld "Group 1" is empty then
add 1 to tMinus
end if
end repeat
subtract tMinus from tCount
put "(" & tCount &" Names)" into fld "LField1"
Klaus's version is probably the shortest. But if you want to access the content of a line you might consider a repeat for each structure, a lot faster. And load the content of the field into a temporary variabel and work on that.
on mouseUp
-- put the text into a variable, speeds things up
put me into myText
put the number of lines of myText into tCount
put 0 into tMinus
-- use a repeat for each construct, speeds things up
repeat for each line aLine in myText
if aLine is empty then add 1 to tMinus
end repeat
put "(" & tCount - tMinus && "Names)" into field "LField1"
end mouseUp
If you want to count the number of empty lines and want to include the last line if that one is empty too, you need to make a correction. Here's a posible solution.
put number of lines of fld 1 - number of lines of replacetext(word 1 to -1 of fld 1,"["&cr&"]+",cr) + offset(last char of fld 1,cr)
You need to replace "fld 1" with the name of your field.
Best,
Mark
The biggest LiveCode group on Facebook: https://www.facebook.com/groups/livecode.developers The book "Programming LiveCode for the Real Beginner"! Get it here! http://tinyurl.com/book-livecode