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!
Moderators: FourthWorld, heatherlaine, Klaus, kevinmiller, robinmiller
-
hamlynart
- Posts: 101
- Joined: Wed Mar 19, 2008 7:10 pm
-
Contact:
Post
by hamlynart » Thu Sep 03, 2009 11:34 am
Hi Folks,
If only this would work:
Code: Select all
on mouseUp
answer the number of empty lines in fld "Group1"
end mouseUp
Instead I'm doing this:
Code: Select all
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"
Is there a simpler way of doing this?
Thanks in advance
Jim H
-
Klaus
- Posts: 14177
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Sep 03, 2009 11:55 am
Hi Jim,
I would:
...
put the num of lines of fld XYZ into all_lines
## We need to modify the content, so we use a copy of the content for that purpose:
put fld XYZ into tTemp
## Get rid of empty lines:
filter tTemp without empty
## Now a little math:
answer all_lines - (the num of lines of tTemp)
...
Best
Klaus
-
bn
- VIP Livecode Opensource Backer

- Posts: 4163
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Thu Sep 03, 2009 12:12 pm
Jim,
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.
Code: Select all
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
regards
Bernd
-
hamlynart
- Posts: 101
- Joined: Wed Mar 19, 2008 7:10 pm
-
Contact:
Post
by hamlynart » Thu Sep 03, 2009 12:12 pm
We need to modify the content, so we use a copy of the content for that purpose
Brilliant Klaus - simply brilliant!
Jim H
-
Klaus
- Posts: 14177
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Sep 03, 2009 12:22 pm
Thank you, Jim!
@Bernd
No "s" after an apostrophe, if there is an "s" before the apostrophe.
Same in german

-
bn
- VIP Livecode Opensource Backer

- Posts: 4163
- Joined: Sun Jan 07, 2007 9:12 pm
Post
by bn » Thu Sep 03, 2009 12:30 pm
@Klaus,
thanks for pointing this out, again a gain of speed, less typing...
in german I would have written Klauses, is that OK?
regards
Bernd
-
Klaus
- Posts: 14177
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Sep 03, 2009 12:49 pm
Hi Bernd,
"Klauses" sounds more like MORE than one Klaus, which is unlikely!

-
malte
- Posts: 1098
- Joined: Thu Feb 23, 2006 8:34 pm
-
Contact:
Post
by malte » Thu Sep 03, 2009 1:16 pm
Well, your knowledge surely is enough for a couple of Klauses.
Cheers,
Malte
-
Klaus
- Posts: 14177
- Joined: Sat Apr 08, 2006 8:41 am
-
Contact:
Post
by Klaus » Thu Sep 03, 2009 1:49 pm
-
Mark
- Livecode Opensource Backer

- Posts: 5150
- Joined: Thu Feb 23, 2006 9:24 pm
-
Contact:
Post
by Mark » Thu Sep 03, 2009 2:54 pm
Hi,
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.
Code: Select all
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