Solved

dim vs private in class

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.

809 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