Page 1 of 1

Detecting an empty line

Posted: Thu Sep 03, 2009 11:34 am
by hamlynart
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

Posted: Thu Sep 03, 2009 11:55 am
by Klaus
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

Posted: Thu Sep 03, 2009 12:12 pm
by bn
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

Posted: Thu Sep 03, 2009 12:12 pm
by hamlynart
We need to modify the content, so we use a copy of the content for that purpose
Brilliant Klaus - simply brilliant!

Jim H

Posted: Thu Sep 03, 2009 12:22 pm
by Klaus
Thank you, Jim!


@Bernd
No "s" after an apostrophe, if there is an "s" before the apostrophe.
Same in german :wink:

Posted: Thu Sep 03, 2009 12:30 pm
by bn
@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

Posted: Thu Sep 03, 2009 12:49 pm
by Klaus
Hi Bernd,

"Klauses" sounds more like MORE than one Klaus, which is unlikely! :D

Posted: Thu Sep 03, 2009 1:16 pm
by malte
Well, your knowledge surely is enough for a couple of Klauses.

Cheers,

Malte

Posted: Thu Sep 03, 2009 1:49 pm
by Klaus
Shouldn't you be working hard in Edinburgh instead of flattering old men here in the forum, Malte? :D :D :D

Posted: Thu Sep 03, 2009 2:54 pm
by Mark
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