Martin H. said:
Hello BB206,
here's an example:
Public Class clsGLOBAL
Private Shared vVariable1 As Integer = 10
Public Shared ReadOnly Property Variable1() As Integer
Get
Return vVariable1
End Get
End Property
End Class
Public Class Test
Private Sub Foo()
MsgBox (clsGLOBAL.Variable1.ToString)
End Sub
End Class
As you can see, the sub "Foo" references clsGLOBAL.Variable1 without the
need of an instance. This is, because it is a shared property. The side
effect of shared properties is that they require a shared variable behind
(vVariable1 is also "Shared"). "Shared" variables can only be used in
"Shared" subs/functions.
If you don't want to use "Shared" variables, you have to create an
instance of that class.
Public Class clsGLOBAL2
Private vVariable1 As Integer = 10
Public ReadOnly Property Variable1() As Integer
Get
Return vVariable1
End Get
End Property
End Class
Public Class Test
Private Sub Foo()
dim ClsGlbl2 As New clsGLOBAL2
MsgBox (ClsGlbl2.Variable1.ToString)
End Sub
End Class
Best regards,
Martin