Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

How do I get the count of childCards in an AddressBook?

8 views
Skip to first unread message

Alan Lord (News)

unread,
Nov 23, 2009, 10:50:51 AM11/23/09
to
Can't work this one out?

abManager =
Components.classes["@mozilla.org/abmanager;1"].getService(Components.interfaces.nsIAbManager);


addressBook = abManager.getDirectory(expAburl);

abCards = addressBook.childCards;

I want to know how many cards are in the abCards collection. I've tried
things like abCards.length and .count but I always get undefined.

TIA

Alan

Leni

unread,
Nov 23, 2009, 6:26:28 PM11/23/09
to Alan Lord (News), dev-ext...@lists.mozilla.org
Alan Lord (News) wrote:
> Can't work this one out?
> abManager =
> Components.classes["@mozilla.org/abmanager;1"].getService(Components.interfaces.nsIAbManager);
>
> addressBook = abManager.getDirectory(expAburl);
>
> abCards = addressBook.childCards;
>
> I want to know how many cards are in the abCards collection.

This should do the trick.

let enm = addressBook.childCards;
let count = 0;

while (enm.hasMoreElements()) {
enm.getNext();
count++;
}

Cheers -

Leni.

Alan Lord (News)

unread,
Nov 24, 2009, 3:17:01 AM11/24/09
to
On 23/11/09 23:26, Leni wrote:

> Alan Lord (News) wrote:
>> I want to know how many cards are in the abCards collection.
>
> This should do the trick.
>
> let enm = addressBook.childCards;
> let count = 0;
>
> while (enm.hasMoreElements()) {
> enm.getNext();
> count++;
> }

Thanks Leni,

I asked on #mozdev lastnight and received the same answer. I had been
expecting a facility like enm.length or enm.count() for example.

It seems a bit long-winded as the count is already displayed in the
status bar at the bottom of the Address Book Window so it does "exist"
in some form already.

But the 'iterate over and count' works so thanks again.

Al

0 new messages