Mega Code Archive

 
Categories / VB.Net Tutorial / Class Module
 

Class that contains instance variable and a property to get and set its value

Module YourClassTest    Sub Main()       Dim obj As New YourClass       Console.WriteLine("Initial course name is: " & obj.YourName & vbCrLf)       obj.YourName = "new Name"       obj.DisplayMessage()    End Sub ' Mains End Module Public Class YourClass    Private yourNameValue As String ' course name for this YourClass    ' property YourName    Public Property YourName() As String       Get ' retrieve yourNameValue          Return yourNameValue       End Get       Set(ByVal value As String) ' set yourNameValue          yourNameValue = value ' store the course name in the object       End Set    End Property ' YourName    ' display a welcome message to the YourClass user    Public Sub DisplayMessage()       Console.WriteLine("Welcome to " & YourName & "!")    End Sub ' DisplayMessage End Class Initial course name is: Welcome to new Name!