When writing property procedures and methods
for a VB6 class, there are three keywords that you can use to
control access to the property or method. Two of these are
straightforward and easy to understand:
- Public: There are no restrictions on
access. - Private: The property or method is available
only from within its own class.
The third keyword is Friend, and its use and
meaning are not well understood. You use Friend when you want a
property or method to be accessible to other objects in the project
but not to the project as a whole. Or, within a component, objects
can access each other’s Friend members, but the program that is
using the component cannot.
For instance, suppose you’re writing a
component as a DLL or ActiveX, and there are several objects in the
component that need to communicate with each other. However, you
don’t want this communication channel to be available to the
program that is calling the component. This is perhaps the most
common use of Friend properties and methods.
Friend properties and methods are not part of a
class’s interface. Also, they don’t appear in the type library of
the class, and they aren’t included when you implement an interface
using the Implements keyword.
Advance your scripting skills to the next level with TechRepublic’s free Visual Basic newsletter, delivered each Friday. Automatically sign up today!