Solved

dim vs private in class

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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

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

Suggested Solutions

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

733 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