Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Friend vs. Public vs. Private

Status
Not open for further replies.

stnkyminky

Programmer
Oct 15, 2001
476
0
0
US
What are the differences between Friend vs. Public and Friend vs. Private? I read in a development web site that Friend was faster/more efficient. Scott
Programmer Analyst
 
Hi stnkyminky,

MSDN:
Public procedures in a class can be called from anywhere, even by controllers of instances of the class.

Declaring a procedure Private prevents controllers of the object from calling the procedure, but also prevents the procedure from being called from within the project in which the class itself is defined.

Friend makes the procedure visible throughout the project, but not to a controller of an instance of the object.

Friend can appear only in form modules and class modules, and can only modify procedure names, not variables or types. Procedures in a class can access the Friend procedures of all other classes in a project. Friend procedures don't appear in the type library of their class. A Friend procedure can't be late bound.


Codefish
 
I will try to resume what Codefish said :
a Friend procedure is public to the project but is not visible outside of it.
 
So, a Friend procedure created in a DLL will not be visible to a program who has a reference to it? Correct.

Ex.

'Defined in the dll
'Class1
Friend Sub
msgbox "Hello"
End Sub

'Program

dim foo as class1

'''' foo. will pulling nothing from the intellisense menu. Scott
Programmer Analyst
 
stnkyminky...

If you declared the Sub in Class1 as private you would have the same result in your intellisense menu.

The difference that friend makes, is that other classes in the same dll file as Class1, CAN access the member.

Thought this might add to your understanding,


Brett. Brett Birkett B.Comp
Systems Analyst
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top