Here this program we create class and in a class create Constructor overloading in vb.net.Let's understand by program.
Employee.vb
Public Class Employee
Dim id, sallary As Integer
Dim name, cate, address As String
Public Sub New(ByVal i As Integer, ByVal n As String, ByVal c As String, ByVal a As String)
id = i
name = n
cate = c
address = a
sallary = 100000
End Sub
Public Sub New(ByVal i As Integer, ByVal n As String, ByVal c As String, ByVal a As String, ByVal s As Integer)
id = i
name = n
cate = c
address = a
sallary = s
End Sub
Public Sub disp()
MsgBox("Id : " & id & vbNewLine & "Name : " & name & vbNewLine & "Address : " & address)
MsgBox("Category : " & cate & vbNewLine & "Sallary : " & sallary)
End Sub
End Class
Form1.vbDim id, sallary As Integer
Dim name, cate, address As String
Public Sub New(ByVal i As Integer, ByVal n As String, ByVal c As String, ByVal a As String)
id = i
name = n
cate = c
address = a
sallary = 100000
End Sub
Public Sub New(ByVal i As Integer, ByVal n As String, ByVal c As String, ByVal a As String, ByVal s As Integer)
id = i
name = n
cate = c
address = a
sallary = s
End Sub
Public Sub disp()
MsgBox("Id : " & id & vbNewLine & "Name : " & name & vbNewLine & "Address : " & address)
MsgBox("Category : " & cate & vbNewLine & "Sallary : " & sallary)
End Sub
End Class
Imports overloading.Employee
Public Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ComboBox1.Text = "CODER" Then
Dim C1 As New Employee(Val(TextBox1.Text), TextBox2.Text, "CODER", TextBox5.Text)
C1.disp()
ElseIf ComboBox1.Text = "PROGRAMMER" Then
Dim C1 As New Employee(Val(TextBox1.Text), TextBox2.Text, "PROGRAMMER", TextBox5.Text, 150000)
C1.disp()
ElseIf ComboBox1.Text = "DEVELOPER" Then
Dim C1 As New Employee(Val(TextBox1.Text), TextBox2.Text, "DEVELOPER", TextBox5.Text, 200000)
C1.disp()
End If
End Sub
End Class
DESIGNINGPublic Class Form1
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
If ComboBox1.Text = "CODER" Then
Dim C1 As New Employee(Val(TextBox1.Text), TextBox2.Text, "CODER", TextBox5.Text)
C1.disp()
ElseIf ComboBox1.Text = "PROGRAMMER" Then
Dim C1 As New Employee(Val(TextBox1.Text), TextBox2.Text, "PROGRAMMER", TextBox5.Text, 150000)
C1.disp()
ElseIf ComboBox1.Text = "DEVELOPER" Then
Dim C1 As New Employee(Val(TextBox1.Text), TextBox2.Text, "DEVELOPER", TextBox5.Text, 200000)
C1.disp()
End If
End Sub
End Class
Comments
Post a Comment