Board index » delphi » Stop counting blank lines with COUNT?

Stop counting blank lines with COUNT?

How do you keep

Label1.Caption := IntToStr(ListBox1.Items.Count);

from including blank lines?

 

Re:Stop counting blank lines with COUNT?


Padre <spe...@dialnet.net> wrote in article
<32d0d130.131597...@news.dialnet.net>...
: How do you keep
:
: Label1.Caption := IntToStr(ListBox1.Items.Count);
:
: from including blank lines?
:

ListBox1.Items.Count is not designed to
separate out certain types of lines and count them,
only to count the total lines in ListBox1.Items.  If
you want to count a special type of item in
ListBox1.Items, you need to write a few lines
of code.

Try this...

cnt := 0;
for x := 0 to ListBox1.Items.Count do
begin
if ListBox1.Items[x] <> ' ' then
cnt := cnt + 1;
end;

Hope this helps -  Rick

Re:Stop counting blank lines with COUNT?


Quote
David Anderson wrote:
> : How do you keep
> :
> : Label1.Caption := IntToStr(ListBox1.Items.Count);
> :
> : from including blank lines?
> :

> Try this...

> cnt := 0;
> for x := 0 to ListBox1.Items.Count do
> begin
> if ListBox1.Items[x] <> ' ' then
> cnt := cnt + 1;
> end;

This is better:

cnt := 0;
for x := 0 to ListBox1.Items.Count-1 do
begin
  if trim(ListBox1.Items[x]) <> '' then
  cnt := cnt + 1;
end;

(trim is only available in 2.x)

Dave.

Other Threads