Logo

Hacker’s Guide to Visual FoxPro
An irreverent look at how Visual FoxPro really works. Tells you the inside scoop on every command, function, property, event and method of Visual FoxPro.

Count

This is a property of each of the OLE collections that are part of VFP. In each case, it tells you how many objects are in that collection.

Usage

nCount = colCollection.Count

Chalk one up for polymorphism. VFP’s native collections, like Forms and Controls, each have their own corresponding Count Property with a distinct name, such as FormCount and ControlCount. The WhateverCount property belongs to the same object that owns the collection. For example, forms have a Controls collection and a ControlCount property.

But the developers got smarter. The new OLE collections, like Projects and Objects, own their own count and they all use the same name for it.

Of course, we don’t need the count for a collection as much as we used to because FOR EACH lets us loop through all the members without worrying about how many there are.

Example

* How many projects are open?
? Application.Projects.Count

See Also

Files, For Each, Objects, Projects, Servers