
Public Class Account
Private mCode As String
Private mName As String
Private mDescription As String
Protected mBalance As Double
Constructor1: Constructor to initialize all the member variables.
Public Sub New(ByVal code, ByVal name,
ByVal description, ByVal balance)
mCode = code
mName = name
mDescription = description
mBalance = balance
End Sub
Constructor2:
Public Sub New()
End Sub
Using Constructor overloading in vb.net
The process of instantiating objects by using overloaded constructors is same as how we do it with a single constructor.
Public Class AccountForm
Private Sub OkButton_Click(ByVal sender As System.Object,
ByVal e As System.EventArgs) Handles OkButton.Click
'Instantiate the Account Class Object by using the Constructor1
Dim myPartyAcc As PartyAccount = New
PartyAccount(txtCode.Text, txtName.Text,
txtDescription.Text, txtBalance.Text, txtAddress.Text, txtPhone.Text)
MessageBox.Show(myPartyAcc.Code)
MessageBox.Show(myPartyAcc.Name)
MessageBox.Show(myPartyAcc.Description)
End Sub
End Class
In the below code, we create the instance of the class and initialize member variables with data entered in the textbox controls by assigning them explicitly.
Public Class AccountForm
Private Sub OkButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Handles OkButton.Click
'Instantiate the Account Class Object by using the Constructor2
Dim myPartyAcc As PartyAccount = New PartyAccount()
myPartyAcc.Code = txtCode.Text
myPartyAcc.Name = txtName.Text
myPartyAcc.Description = txtDescription.Text
myPartyAcc.Balance = txtBalance.Text
myPartyAcc.Address = txtAddress.Text
myPartyAcc.Phone = txtPhone.Text
MessageBox.Show(myPartyAcc.Code)
MessageBox.Show(myPartyAcc.Name)
MessageBox.Show(myPartyAcc.Description)
End Sub
End Class
Copyright © 2012 - All Rights Reserved - VKInfotek.com