Share via


Member Scope

This content is no longer actively maintained. It is provided as is, for anyone who may still be using these technologies, with no warranties or claims of accuracy with regard to the most recent product version or service release.

The set of public variables, methods, properties, and events described in a class module define the interface for an object. The interface consists of the object members that are available to a programmer who's using the object from code.

A class module can also include private members that are not available to a programmer working with the object. You can create private variables, methods, properties, and events that are used by other procedures within the class module but are not part of the object's public interface. Additionally, constants, user-defined types, and Declare statements within a class module must always be private.

By default, Sub, Function, and Property procedures within a class module are public. Variables declared with the Dim statement, on the other hand, are private. It is a good idea to preface variable declarations and procedure definitions with either the Public or Private keyword, so that it is clear to you or any other developer looking at the class which elements are intended to be public or private.

In addition, you can declare a Sub, Function, or Property****procedure with the Friend keyword. The Friend keyword makes a procedure private to the project: The procedure is available to any code running within the project, but it is not available to a referencing project. For more information about the Friend keyword, search the Visual Basic Reference Help index for "Friend keyword."

See Also

Why Build Your Own Objects? | Basic Class Concepts | Creating Property Procedures | Creating Events and Event Procedures | Extending Objects Through Interfaces | Designing Object Models | Creating Custom Objects for Web Pages