By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
443,333 Members | 1,020 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 443,333 IT Pros & Developers. It's quick & easy.

Public vs Friend

P: n/a
I have read and re-read VB.Net's help on scope of variables but darned if I can understand the difference between Friend and Public variables?
--
Dennis in Houston
Nov 20 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
I have used it for controls and such.

Lets say you have a module wth code that needs to be public for other member
of your project, but you want it to be hidden from the end user. Declare it
Friend. If you want it to be accessed for everything then declare it
public.

I haven't found many times for the need, but does arise. For another
instance. I made a message box control that had 3 forms. I needed a class
to interact with the forms, but I didn't want a user to grab the forms, so I
made them friend classes.

Hope that help a little

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
I have read and re-read VB.Net's help on scope of variables but darned if I can understand the difference between Friend and Public variables? --
Dennis in Houston

Nov 20 '05 #2

P: n/a
I think I understand. Public class1 lets me access class1 in my assembly as well as other users who add my assembly to their projects. If I use Friend, then I can access class 1 in my assembly but others using the assembly in their projects cannot access class1. Thanks.
--
Dennis in Houston
"Lespaul36" wrote:
I have used it for controls and such.

Lets say you have a module wth code that needs to be public for other member
of your project, but you want it to be hidden from the end user. Declare it
Friend. If you want it to be accessed for everything then declare it
public.

I haven't found many times for the need, but does arise. For another
instance. I made a message box control that had 3 forms. I needed a class
to interact with the forms, but I didn't want a user to grab the forms, so I
made them friend classes.

Hope that help a little

"Dennis" <De****@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
I have read and re-read VB.Net's help on scope of variables but darned if

I can understand the difference between Friend and Public variables?
--
Dennis in Houston


Nov 20 '05 #3

P: n/a
friend vars are available to other members of the same package (i mean same
Namespace)
Public vars are available to other classes - even if not in the same
package - er Namespace

Java calls it package
VB calls it Namespace
"Dennis" <De****@discussions.microsoft.com> wrote in message
news:39**********************************@microsof t.com...
I have read and re-read VB.Net's help on scope of variables but darned if I can understand the difference between Friend and Public variables? --
Dennis in Houston

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.732 / Virus Database: 486 - Release Date: 7/29/2004
Nov 20 '05 #4

P: n/a
"Hal Rosser" <hm******@bellsouth.net> wrote in message
news:ig**************@bignews1.bellsouth.net...
friend vars are available to other members of the same package
(i mean same Namespace)
Public vars are available to other classes - even if not in the same
package - er Namespace


Would that that were True.

In my experience, "Friend" only exposes stuff within the current
/Assembly/, and /not/, as I would /dearly/ like, the given Namespace!

Regards,
Phill W.
Nov 20 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.