The VBA Collection
has 5 members, all of which are methods: Add
, Count
, Item
, _NewEnum
and Remove
.
Of the 5 members, the Count
method looks like it could/should be a getter rather than a method.
Is this a legacy of OOP/MS design from the early days of VB6? Did the designers of the Collection anticipate a time when Count
might need to be a method, and designate Count
as a method so that some future behavioral change wouldn't break the interface/COM?
EDIT As Jim Hewitt points out in the comments, the online documentation suggests that Count
is a property, but Object Browser and the MIDL suggest otherwise.
Here's the documentation for VB6's Collection.Count
Property
Returns a Long (long integer) containing the number of objects in a collection. Read-only.
But the VB6 Object Browser shows this:
And in Excel 2016, Count
sure looks lonely and like it wants to be a getter...
EDIT 22/Sep/16:
I referred back to Hardcore Visual Basic 5 by Bruce McKinney...
This doesn't exactly explain why Collection.Count
is a method, but it does go some way to answering why I can't know why Collection.Count
is a method:
On knowing the unknowable:
anything you think you know about the implementation of a Collection might be wrong for this version and probably will be wrong for the next version.
On Implementation details:
The Collection class provided with Visual Basic version 4 was a good 1 version. The Collection class provided with Visual Basic version 5 is not a good 2 version. Users offered many complaints and suggestions. None of them were implemented.
On Collections:
What is a Collection? You know its user interface, but you don’t really know what internal data structure makes it work. Normally, this isn’t a concern. Who cares how it works as long as it works? But, on second thought, the internal implementation is bound to affect the efficiency of operations. If some operations are less efficient than others, it might be nice to avoid the slow ones.
On Collection.Item
:
Visual Basic could have made [
Collection.Item
] work [as a property]. (It was requested.)