2.5 Objects

  Within the VBA Environment, an object is a set of related variables (section 2.3), procedures (section 2.4) and events. Collectively, the variables, procedures and events that make up an object are called the object’s members. The term method can be used with the same meaning as procedure member. Each object is identified by a unique identifier which is a data value (section 2.1) whose value type (section 2.1) is object reference. An object’s members are accessed by invoking methods and evaluating member variables and properties using this object reference. Because a specific data value can simultaneously exist in many variables there can be many ways to access any particular object.

An object’s events are attachment points to which specially named procedures can be dynamically associated. Such procedures are said to handle an object’s events. Using the RaiseEvent statement of the VBA language, methods of an object can call the procedures handling a member event of the object without knowing which specific procedures are attached.

All variables and events that make up an object have the same extent (section 2.3) which begins when the containing object is explicitly or implicitly created and concludes when it is provably inaccessible from all procedures.

A class is a declarative description of a set of objects that all share the same procedures and have a similar set of variables and events. The members of such a set of objects are called instances of the class. A typical class can have multiple instances but VBA also allows the definition of classes that are restricted to having only one instance. All instances of a specific class share a common set of variable and event declarations that are provided by the class but each instance has its own unique set of variables and events corresponding to those declarations.

The access control options of VBA language declarations can limit which procedures within a VBA Environment are permitted to access each object member defined by a class. A member that is accessible to all procedures is called a public member and the set of all public procedure members and variable members of a class is called the public interface of the class. In addition to its own public interface the definition of a class can explicitly state that it implements the public interface of one or more other classes. A class or object that is explicitly defined to implement a public interface is said to conform to that interface. In this case the conforming class MUST include explicitly tagged definitions for all of the public procedure and variable members of all of the public interfaces that it implements.

When a variable is defined with the name of a class as its declared type (section 2.2) then that variable can only contain object references to instances of that specific named class or object references to objects that conform to the public interface of the named class.