This is the corrected version - much thanks to
Mattias & Rob for showing me the errors of my
ways.

For you consideration, this is a discussion
of shared methods, the use of properties, and
other implications for shared variables in
classes. These is the third of four parts
of the How To. Part IV will follow soon.

Imports System.Console
Class clsTestShare
Private Shared mlngValue As Long = 6
Private mlngNonShared As Long
' NOTE 1
Property lngValue() As Long
Get
lngValue = mlngValue
End Get
Set
mlngValue = value
End Set
End Property
' NOTE 2
Public Shared Property s_lngValue() As Long
Get
s_lngValue = mlngValue
End Get
Set
mlngValue = value
End Set
End Property
' NOTE 3
Public Shared Property x_lngValue() As Long
Get
' x_lngValue = mlngNonShared
End Get
Set
' mlngNonShared = value
End Set
End Property
' NOTE 4
Public Shared Function GetTheValue() As Long
Return mlngValue
End Function
' NOTE 5
Public Shared Function GetNonSharedValue() As Long
' Return mlngNonShared
Return 0
End Function
' NOTE 6
Public Function GetShared() As Long
Return mlngValue
End Function
Public Function AnotherGetNonShared() As Long
Return mlngNonShared
End Function
' NOTE 7
Public Sub New(ByVal lngArgvValue As Long)
mlngNonShared = lngArgvValue
End Sub
End Class
Module modTestShare
Sub Main()
' NOTE 8
' WriteLine("Value = " & clsTestShare.lngValue.ToString())
' NOTE 9
WriteLine("Value = " & clsTestShare.GetTheValue.ToString())
' NOTE 10
WriteLine("Value = " & clsTestShare.s_lngValue.ToString())
' NOTE 11
WriteLine("Value = " & clsTestShare.x_lngValue.ToString())
' NOTE 12
Dim PatsClass As New clsTestShare(9)
' NOTE 13
WriteLine("Value = " & PatsClass.lngValue.ToString())
' NOTE 14
WriteLine("Value = " & PatsClass.GetTheValue.ToString())
' NOTE 15
WriteLine("Value = " & PatsClass.AnotherGetNonShared.ToString())
' NOTE 16
WriteLine("Value = " & PatsClass.x_lngValue.ToString())
End Sub
End Module


NOTE 1
A Public nonshared property. They only work within an instantiated object.
They may access shared and non shared variables, methods, and properties
of the class.

NOTE 2
A Public shared property. It works with a class definition name or an
instantiated object. Shared properties may only access shared variables
of the class, not nonshared variables. It may also call other shared
properties and methods of the class but not nonshared properties or
nonshared methods.

NOTE 3
A Public shared property. This property attempts to access a
nonshared variable - Bzzzzz compiler generates an error.

NOTE 4
A Public shared method. It works with a class definition name or an
instantiated object. Shared methods may only access shared variables
of the class, not nonshared variable. It may also call other shared
properties and methods of the class but not nonshared properties or
nonshared methods.

NOTE 5
A Public shared method. This method attempts to access a nonshared
variable - Bzzzzz compiler generates an error.

NOTE 6
A Public nonshared method. They only work within an instantiated object.
They may access shared and non shared variables, methods, and properties
of the class.

NOTE 7
In this example, the constructor is a nonshared method so it can
access any variable shared or nonshared. Please note that the
constructor can also be a shared method but that's the discussion
for Part IV.

See Kathleen, I did finally get closer to discussing shared
constructors 8-).

NOTE 8
Send lngValue is a property of the class, it is not accessible
through the class name definition rather it can only be used
with an instantiated object of the class.

NOTE 9
GetTheValue is a shared method therefore is accessible via the class
definition name.

NOTE 10
s_lngValue is a shared property therefore is accessible via the class
definition name.

NOTE 11
x_lngValue is a shared property but there is no code in the Get property.
You should not do this, however if you do write Get properties without
code then await the final release to determine the value retrieved. It
is too early to guarantee that zero is the returned value.

NOTE 12
Instantiate a instance of the class and pass an initialization value
to the constructor (nonshared NEW method in this example). At this
point I can access any shared or nonshared method of the class using
the instantiated object. I can also access any property of instantiated
object. Finally, I can access and pubic or public shared variable of
the class. Variable reference was covered in Part I of my How To for
shared class variables.

NOTE 13
Nonshared property is available through the instantiated object.

NOTE 14
Shared method is available through the instantiated object.

NOTE 15
Nonshared method is available through the instantiated object.

NOTE 16
Shared property is available through the instantiated object.

Output of program is:

Value = 6
Value = 6
Value = 0
Value = 6
Value = 6
Value = 9
Value = 0