stu nicholls dot com | menu - Professional dropdown #3

click here


Properties


Creating a Property procedure

Example:
Module Module1
Sub Main()
Module2.Prop1 = 2
System.Console.WriteLine("Prop1=" & Module2.prop1)
End Sub
End Module
Module Module2
Private PropertyValue As Integer
Public Property prop1() As Integer
Get
Return PropertyValue
End Get
Set(ByVal value As Integer)
PropertyValue = value
End Set
End Property
End Module

Example:Using Index Property
Module Module1
Private Data(200) As Integer
Public Property Property1(ByVal Index As Integer) As Integer
Get
Return Data(Index)
End Get
Set(ByVal value As Integer)
Data(Index) = value
End Set
End Property
End Module
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Module1.Property1(5) = 1
MsgBox(Module1.Property1(5))
End Sub
End Class
Public Class Form1
Public ob1 As New class1()
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Module1.Property1(5) = 1
MsgBox(Module1.Property1(5))
ob1.Property1(2) = 55
MsgBox(ob1.Property1(2)) End Sub
End Class
Public Class class1
Private Data(200) As Integer
Public Property Property1(ByVal Index As Integer) As Integer
Get
Return Data(Index)
End Get
Set(ByVal value As Integer)
Data(Index) = value
End Set
End Property
End Class

Creating Class(Shared) Properties Public Class Form1
Public Class mathematics
Shared data As Integer = 0
Shared Property property1()
Get
Return data
End Get
Set(ByVal value)
data = value
End Set
End Property
End Class
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
mathematics.property1 = 7
MessageBox.Show("Property Set")
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
TextBox1.Text = mathematics.property1
End Sub

Next>>Types of properties


comments powered by Disqus
click here
Footer1