Solved

dim vs private in class

Posted on 2011-09-14
5
349 Views
Last Modified: 2012-06-21
Hi,

a question I've been stumbling upon just now but can't figure out.

Whats the difference between for example:

Dim x as int32
private x as int32

within a class?
0
Comment
Question by:Mutsop
5 Comments
 
LVL 39

Assisted Solution

by:appari
appari earned 125 total points
ID: 36534488
Dim is used to declare variables and allocate memory space.
Private used as access modifier for the variable, We can optionally omit Dim by declaring the variable after the access modifier
If we don't specify an access modifier on a variable it will be Private by default.

0
 
LVL 15

Accepted Solution

by:
Minh Võ Công earned 150 total points
ID: 36534845
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 125 total points
ID: 36534873
In a class, they are the same. However, in a structure, Dim becomes Public.

So, as a good practice, and to prepare your declarations from eventual copy and somewhere else, it is better to use Private to declare the members of a class.
0
 
LVL 5

Assisted Solution

by:speak2ab
speak2ab earned 100 total points
ID: 36534961

Dim - declare and allocate space for a variable Private - access modifier specifier

I believe your question comes from the fact that you sometimes see things like:

Class MyDemoCLass
   Dim mVar1 As Integer
   Private mVar2 As Integer
End Class

In the above example mVar1 and mVar2 declarations are logically equivalent - they both boil down to Private Dim mVar as Integer

This happens due to:

    Implicit Use of Dim. If you specify any of the modifiers Public, Protected, Friend, Protected Friend, Private, Shared, Shadows, Static, ReadOnly, or WithEvents, you can optionally omit the Dim keyword.

    Public maximumAllowed As Double
    Protected Friend currentUserName As String
    Private salary As Decimal
    Static runningTotal As Integer

(source: http://stackoverflow.com/questions/5401372/difference-between-dim-and-private-inside-a-vb-net-form)

Some very clear example can be found on microsofts page:
http://msdn.microsoft.com/en-us/library/7ee5a7s1%28v=vs.80%29.aspx
0
 
LVL 3

Author Closing Comment

by:Mutsop
ID: 36535151
Thanks alot :)
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.
Need to grow your business through quality cloud solutions? With everything required to build a cloud platform and solution, you may feel like the distance between you and the cloud is quite long. Help is here. Spend some time learning about the Con…

930 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now