Home All Groups Group Topic Archive Search About

by default, public or private?

Author
16 Feb 2006 4:35 PM
prefersgolfing
I'm trying to find on MSDN, or someplace, that speaks to variables being
public or private by default. Anyone know where? Thanks.

Author
15 Feb 2006 8:57 PM
Cerebrus99
Hi all,

"If the Dim statement is used (in Visual Basic .NET) or no access modifier
is used (in Visual C#), the variable is considered private in Visual C# and
Visual Basic .NET classes, Public in Visual Basic .NET structures, and
private in Visual C# structures. Methods do not require an access modifier.
If no access modifier is specified, the method is Private by default if in a
class or structure in C#, and Public if in a class or structure in Visual
Basic .NET."

--- MCAD/MCSD Training Kit Windows Apps. Exam 70-306.

Joe wrote :
> The variable is private to the module BUT public within the module.

Hi Joe,

I think you are not entirely right. There is no such thing as "public within
the module". The definition of a private variable is one that is not visible
*outside* of the type to which it belongs (Class or struct). "Private" is
the most you can limit the access level, and even all Private variables can
be freely accessed within the class they are declared.

> I believe it depends more on where the variable is declared.
Yes, you are right about that. As above, variables in VB.NET structures are
by default Public.

Show quoteHide quote
"prefersgolfing" <prefersgolf***@hotmail.com> wrote in message
news:uq#VGcxMGHA.1532@TK2MSFTNGP12.phx.gbl...
> I'm trying to find on MSDN, or someplace, that speaks to variables being
> public or private by default. Anyone know where? Thanks.
>
>
Author
16 Feb 2006 9:19 PM
Joe Sutphin
Actually, no I'm right. You're only pointing out a semantical issue.

Since we're in the VB newsgroup, the posts about other languages don't
apply.


Show quoteHide quote
"Cerebrus99" <zorg***@sify.com> wrote in message
news:%23FXskuzMGHA.2992@tk2msftngp13.phx.gbl...
> Hi all,
>
> "If the Dim statement is used (in Visual Basic .NET) or no access modifier
> is used (in Visual C#), the variable is considered private in Visual C#
> and
> Visual Basic .NET classes, Public in Visual Basic .NET structures, and
> private in Visual C# structures. Methods do not require an access
> modifier.
> If no access modifier is specified, the method is Private by default if in
> a
> class or structure in C#, and Public if in a class or structure in Visual
> Basic .NET."
>
> --- MCAD/MCSD Training Kit Windows Apps. Exam 70-306.
>
> Joe wrote :
>> The variable is private to the module BUT public within the module.
>
> Hi Joe,
>
> I think you are not entirely right. There is no such thing as "public
> within
> the module". The definition of a private variable is one that is not
> visible
> *outside* of the type to which it belongs (Class or struct). "Private" is
> the most you can limit the access level, and even all Private variables
> can
> be freely accessed within the class they are declared.
>
>> I believe it depends more on where the variable is declared.
> Yes, you are right about that. As above, variables in VB.NET structures
> are
> by default Public.
>
> "prefersgolfing" <prefersgolf***@hotmail.com> wrote in message
> news:uq#VGcxMGHA.1532@TK2MSFTNGP12.phx.gbl...
>> I'm trying to find on MSDN, or someplace, that speaks to variables being
>> public or private by default. Anyone know where? Thanks.
>>
>>
>
>
Author
17 Feb 2006 10:03 AM
Cor Ligthert [MVP]
Joe,

See my other answer to you,

Cor
Author
17 Feb 2006 1:20 PM
Joe Sutphin
Cor,

See my response to you

Joe
--

Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23TRD1k6MGHA.1192@TK2MSFTNGP11.phx.gbl...
> Joe,
>
> See my other answer to you,
>
> Cor
>
Author
16 Feb 2006 4:20 PM
Cerebrus99
Lolz ! I think I'm gonna like you, Joe !

Regards,

Cerebrus.

Show quoteHide quote
"Joe Sutphin" <joesutp***@earthlink.net> wrote in message
news:#0qV3T8MGHA.2780@TK2MSFTNGP10.phx.gbl...
> Cor,
>
> See my response to you
>
> Joe
> --
>
> "Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
> news:%23TRD1k6MGHA.1192@TK2MSFTNGP11.phx.gbl...
> > Joe,
> >
> > See my other answer to you,
> >
> > Cor
> >
>
>
Author
16 Feb 2006 4:41 PM
Carlos J. Quintero [VB MVP]
By default they are private. You can see the icons in the ClassView window.
--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com


Show quoteHide quote
"prefersgolfing" <prefersgolf***@hotmail.com> escribió en el mensaje
news:uq%23VGcxMGHA.1532@TK2MSFTNGP12.phx.gbl...
> I'm trying to find on MSDN, or someplace, that speaks to variables being
> public or private by default. Anyone know where? Thanks.
>
Author
16 Feb 2006 8:27 PM
Joe Sutphin
I'm not sure that's exactly accurate. In this example

Module Module1

Dim x As String

Sub Main()

x = "This is a string"

Debug.WriteLine(x)

End Sub

End Module



The variable is private to the module BUT public within the module.

I believe it depends more on where the variable is declared.

Joe
--

Show quoteHide quote
"Carlos J. Quintero [VB MVP]" <carlosq@NOSPAMsogecable.com> wrote in message
news:eeELafxMGHA.3936@TK2MSFTNGP10.phx.gbl...
> By default they are private. You can see the icons in the ClassView
> window.
> --
>
> Best regards,
>
> Carlos J. Quintero
>
> MZ-Tools: Productivity add-ins for Visual Studio
> You can code, design and document much faster:
> http://www.mztools.com
>
>
> "prefersgolfing" <prefersgolf***@hotmail.com> escribió en el mensaje
> news:uq%23VGcxMGHA.1532@TK2MSFTNGP12.phx.gbl...
>> I'm trying to find on MSDN, or someplace, that speaks to variables being
>> public or private by default. Anyone know where? Thanks.
>>
>
>
Author
17 Feb 2006 9:51 AM
Carlos J. Quintero [VB MVP]
Hi Joe,

What are you talking about here? The scope of a class/module variable refers
to its visibility outside the class/module where they are declared. Of
course that a class or module-level variable is reachable within the
class/module, how could it be otherwise?

--

Best regards,

Carlos J. Quintero

MZ-Tools: Productivity add-ins for Visual Studio
You can code, design and document much faster:
http://www.mztools.com

Show quoteHide quote
"Joe Sutphin" <joesutp***@earthlink.net> escribió en el mensaje
news:ORP86dzMGHA.2580@TK2MSFTNGP14.phx.gbl...
> I'm not sure that's exactly accurate. In this example
>
> Module Module1
> Dim x As String
> Sub Main()
> x = "This is a string"
> Debug.WriteLine(x)
> End Sub
> End Module
>
> The variable is private to the module BUT public within the module.
>
> I believe it depends more on where the variable is declared.
>
> Joe
> --
Author
17 Feb 2006 10:04 AM
Cor Ligthert [MVP]
Joe,

> The variable is private to the module BUT public within the module.
> I believe it depends more on where the variable is declared.
>
I don't see what you mean, a variable is default private it nothing is add
to it.
We can forget the DIM keyword because that adds nothing (and therefore the
same as not used in C#).

A value delclared inside a method can only be private to that method. A
value on Class level can have other access rights. (See for that the message
from Randy).

A module is nothing more than a Class which has all his members shared
global to the application (main class).

Cor
Author
17 Feb 2006 12:49 PM
Joe Sutphin
For all intents and purposes DIM and Private are equal.

There are three levels of scope. All variables declared within a procedure
are private.

Variables declared within a module are private to that module using either
Dim or Private.

Variables declared within a module as Public are accessible to any procedure
inside or outside of that module.

Again, my original statement stands, it depends on where you declare the
variable. Not declaring it properly is just wrong!

Joe
--
Show quoteHide quote
"Cor Ligthert [MVP]" <notmyfirstn***@planet.nl> wrote in message
news:%23Pd6Nl6MGHA.2604@TK2MSFTNGP09.phx.gbl...
> Joe,
>
>> The variable is private to the module BUT public within the module.
>> I believe it depends more on where the variable is declared.
>>
> I don't see what you mean, a variable is default private it nothing is add
> to it.
> We can forget the DIM keyword because that adds nothing (and therefore the
> same as not used in C#).
>
> A value delclared inside a method can only be private to that method. A
> value on Class level can have other access rights. (See for that the
> message from Randy).
>
> A module is nothing more than a Class which has all his members shared
> global to the application (main class).
>
> Cor
>
>
>
>
>
>
>
Author
17 Feb 2006 9:42 AM
R. MacDonald
Hello, Golfer,

Try:

http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcn7/html/vbconaccessibility.asp

Or search help for "scope".

But, the fact there is discussion about this means many people are in
doubt about it.  May I humbly suggest that you always declare your names
explicitly.

Cheers,
Randy


prefersgolfing wrote:

Show quoteHide quote
> I'm trying to find on MSDN, or someplace, that speaks to variables being
> public or private by default. Anyone know where? Thanks.
>
>