Solved

dim vs private in class

Posted on 2011-09-14
5
347 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
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 …
It is a freely distributed piece of software for such tasks as photo retouching, image composition and image authoring. It works on many operating systems, in many languages.
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

743 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

13 Experts available now in Live!

Get 1:1 Help Now