Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

dim vs private in class

Posted on 2011-09-14
5
Medium Priority
?
363 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
5 Comments
 
LVL 39

Assisted Solution

by:appari
appari earned 500 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 600 total points
ID: 36534845
0
 
LVL 40

Assisted Solution

by:Jacques Bourgeois (James Burger)
Jacques Bourgeois (James Burger) earned 500 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 400 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: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying 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

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)…
Many of us here at EE write code. Many of us write exceptional code; just as many of us write exception-prone code. As we all should know, exceptions are a mechanism for handling errors which are typically out of our control. From database errors, t…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Screencast - Getting to Know the Pipeline

610 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