RE: silly, probably meaninigless question

Tech-Archive recommends: Speed Up your PC by fixing your registry



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.

.



Relevant Pages

  • Re: silly, probably meaninigless question
    ... In my opinion are you describing the differences between Private and Dim ... Dim is only used to declare variables. ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.vb)
  • Re: WideCharToMultiByte and utf-8
    ... Private Declare Function lstrlenW Lib "kernel32" As ... Private Function String_to_UTF8(strInput As String) As String ... Dim UTF8Buffer() As Byte ...
    (microsoft.public.vb.general.discussion)
  • Re: MiniDumpWriteDump
    ... Private Type EXCEPTION_POINTERS ... > Private Declare Function GetCurrentProcessId Lib "kernel32" As Long ... > Dim hFile As Long ...
    (microsoft.public.vb.winapi)
  • RE: Specify custom disabled text color in ToolStripProfessionalRen
    ... I think we may repeat the ... Private Shared Function FlipSizeAs Size ... Dim item1 As ToolStripItem = e.Item ... Microsoft Online Community Support ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Early-bound
    ... > variables by "dim" them at the start of each procedure. ... > good coding or should the dim statement be put at the begining of the ... If you declare it in each procedure then each declaration is a different ... variable and all are private to their respective procedure. ...
    (microsoft.public.vb.general.discussion)