472,805 Members | 938 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,805 software developers and data experts.

by default, public or private?

I'm trying to find on MSDN, or someplace, that speaks to variables being
public or private by default. Anyone know where? Thanks.
Feb 16 '06 #1
11 5549
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" <pr************@hotmail.com> escribió en el mensaje
news:uq****************@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.

Feb 16 '06 #2
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
--

"Carlos J. Quintero [VB MVP]" <ca*****@NOSPAMsogecable.com> wrote in message
news:ee**************@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" <pr************@hotmail.com> escribió en el mensaje
news:uq****************@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.


Feb 16 '06 #3
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" <pr************@hotmail.com> wrote in message
news:uq**************@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.

Feb 16 '06 #4
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.
"Cerebrus99" <zo*****@sify.com> wrote in message
news:%2****************@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" <pr************@hotmail.com> wrote in message
news:uq**************@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.


Feb 16 '06 #5
Hello, Golfer,

Try:

http://msdn.microsoft.com/library/de...essibility.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:
I'm trying to find on MSDN, or someplace, that speaks to variables being
public or private by default. Anyone know where? Thanks.

Feb 17 '06 #6
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

"Joe Sutphin" <jo********@earthlink.net> escribió en el mensaje
news:OR**************@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
--

Feb 17 '06 #7
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



Feb 17 '06 #8
Joe,

See my other answer to you,

Cor
Feb 17 '06 #9
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
--
"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@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


Feb 17 '06 #10
Cor,

See my response to you

Joe
--

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Joe,

See my other answer to you,

Cor

Feb 17 '06 #11
Lolz ! I think I'm gonna like you, Joe !

Regards,

Cerebrus.

"Joe Sutphin" <jo********@earthlink.net> wrote in message
news:#0**************@TK2MSFTNGP10.phx.gbl...
Cor,

See my response to you

Joe
--

"Cor Ligthert [MVP]" <no************@planet.nl> wrote in message
news:%2****************@TK2MSFTNGP11.phx.gbl...
Joe,

See my other answer to you,

Cor


Feb 17 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ng Hun Yang | last post by:
I have a class that has a default constructor that initializes the class's variables. Now I want to add a new constructor to skip the initialization. My attempt: class Integer { public: class...
3
by: Phil Certain | last post by:
Hi I'm building a site that has publicly available pages and password protected pages. Publicly available pages reside in: /public and password protected pages reside in: /private
19
by: Andrew J. Marshall | last post by:
I want to create a class that must receive a parameter when instantiated. In other words, I do not want it to have a "Public Sub New()". 1) Does VB.NET create a default public constructor if I do...
3
by: Marty McFly | last post by:
Hello, I have a control class that inherits from System.Web.UI.WebControls.Button. When I drag this control from the "My User Controls" tab in the toolbox onto the form, I want it to reflect the...
5
by: Wonder | last post by:
How can I create or use the msgobx to show a message without a default button. The user has explicity to click on the button, so the msgbox closes it. Thanks,
6
by: Tony Johansson | last post by:
Hello!! If you write private class Test {} you have a private class If you write public class Test {} you have a public class If you write protected class Test {} you have a protected class If...
12
by: Anil Gupte | last post by:
I wrote my Windows Service first as a regular Windows Exe because it is easier to debug. In that I used AppDir = Application.ExecutablePath.Substring(0,...
2
by: Jeff | last post by:
Hi I'm trying to achieve a scenario where I have c# files that are compiled dynamically, the assemblies are then loaded in a different AppDomain, I call a simple method from the object, and then...
5
by: * Tong * | last post by:
Hi, I couldn't figure out the answer myself about the default constructor -- does C++ create it by default? If yes, under what circumstances? Actually, I've found out the partial answer myself...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 2 August 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: erikbower65 | last post by:
Using CodiumAI's pr-agent is simple and powerful. Follow these steps: 1. Install CodiumAI CLI: Ensure Node.js is installed, then run 'npm install -g codiumai' in the terminal. 2. Connect to...
0
linyimin
by: linyimin | last post by:
Spring Startup Analyzer generates an interactive Spring application startup report that lets you understand what contributes to the application startup time and helps to optimize it. Support for...
0
by: kcodez | last post by:
As a H5 game development enthusiast, I recently wrote a very interesting little game - Toy Claw ((http://claw.kjeek.com/))。Here I will summarize and share the development experience here, and hope it...
0
by: Taofi | last post by:
I try to insert a new record but the error message says the number of query names and destination fields are not the same This are my field names ID, Budgeted, Actual, Status and Differences ...
5
by: DJRhino | last post by:
Private Sub CboDrawingID_BeforeUpdate(Cancel As Integer) If = 310029923 Or 310030138 Or 310030152 Or 310030346 Or 310030348 Or _ 310030356 Or 310030359 Or 310030362 Or...
0
by: lllomh | last post by:
Define the method first this.state = { buttonBackgroundColor: 'green', isBlinking: false, // A new status is added to identify whether the button is blinking or not } autoStart=()=>{
0
by: Mushico | last post by:
How to calculate date of retirement from date of birth
2
by: DJRhino | last post by:
Was curious if anyone else was having this same issue or not.... I was just Up/Down graded to windows 11 and now my access combo boxes are not acting right. With win 10 I could start typing...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.