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
Public Shared Function GetTheValue() As Long
Return mlngValue
End Function
Public Shared Function GetNonSharedValue() As Long
' NOTE 2
' Return mlngNonShared
Return 0
End Function
' NOTE 3
Public Function GetShared() As Long
Return mlngValue
End Function
Public Function AnotherGetNonShared() As Long
Return mlngNonShared
End Function
' NOTE 4
Public Sub New(ByVal lngArgvValue As Long)
mlngNonShared = lngArgvValue
End Sub
End Class
Module modTestShare
Sub Main()
' NOTE 5
' WriteLine("Value = " & clsTestShare.lngValue.ToString())
' NOTE 6
WriteLine("Value = " & clsTestShare.GetTheValue.ToString())
' NOTE 7
Dim PatsClass As New clsTestShare(9)
' NOTE 8
WriteLine("Value = " & PatsClass.lngValue.ToString())
' NOTE 9
WriteLine("Value = " & PatsClass.GetTheValue.ToString())
' NOTE 10
WriteLine("Value = " & PatsClass.AnotherGetNonShared.ToString())
End Sub
End Module


NOTE 1
Properties can not be shared. Therefore they only work for an
instantiated object.

NOTE2
Shared methods can only access shared variables of the class.

NOTE 3
Normal (nonshared) methods can acess both shared and nonshared
variables of the class. This is because the method exists within
the context of the instatiated object therefore any nonshared
variables of the class also exist.

NOTE 4
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 5
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 6
GetTheValue is a shared method therefore is accessible via the class
definition name.

NOTE 7
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 8
Property is available through the instantiated object.

NOTE 9
Shared method is available through the instantiated object.

NOTE 10
Nonshared method is available through the instantiated object.

Output from this program is as follows:
Value = 6
Value = 6
Value = 6
Value = 9