Hi Matt,
Thank you for posting.
I think there're three main differences between Dim and Private.
1. Elements you can declare with Dim are different from those with Private.
Dim is only used to declare variables. However, Private can be used for
Interface, Class, Structure, Structure members, Procedure, Property, Member
variables,Constant, Enumeration, Event, External declaration and Delegate.
2. Declaration context within which you can use Dim and Private are
different.
Dim can be used in a procedure or function, however Private can't. For
example, suppose there's a procedure named MyProcedure. We could use Dim
to declare the variable in MyProcedure, but we couldn's use Private to
declare it.
Sub MyProcedure()
Dim localVar As String
' we couldn't use Private to declare a variable in a procedure
' the following code will cause an error
Private localVar1 As String
End Sub
3. Elements declared with Dim has the default access level. Elements
declared with Private are always private.
For example, if you use Dim to declare a varible in a Class, the variable
is private because in VB.NET the default access level of member variable in
class is private.
On the contrary, if you use Dim to declare a variable in a Structure, the
variable is public because in VB.NET the default access level of member
variable in structure is public.
Hope this helps.
If you have anything unclear, please feel free to let me know.
Sincerely,
Linda Liu
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscriptions/managednewsgroups/default.aspx#notif
ications.
Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscriptions/support/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.