Project EmpClass (PowerPoint is classesintro
– using EmpClass)
Public Class
frmEmp
Inherits
System.Windows.Forms.Form
Dim aEmp As New Emp
Private Sub btnMsg_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnMsg.Click
aEmp.PrintMsgBox()
MessageBox.Show(aEmp.RtnStr())
MessageBox.Show(CStr(aEmp.GetYrSal()))
End Sub
Private Sub btnGetEmp_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnGetEmp.Click
aEmp.mId = InputBox("Enter Employee ID",
"Employee information", "")
aEmp.mName = InputBox("Enter Employee Name",
"Employee information", "")
aEmp.mType = InputBox("Enter Employee Type",
"Employee information", "")
aEmp.mWkSal = InputBox("Enter Employee Salary",
"Employee information", "")
With lstEmp.Items()
.Add(aEmp.mId)
.Add(aEmp.mName)
.Add(aEmp.mType)
.Add(aEmp.mWkSal)
End With
End Sub
End Class
Public Class
Emp
Public mId As String
Public mName As String
Public mType As String
Public mWkSal As Single
Public Sub
PrintMsgBox()
MessageBox.Show(mId & " - " & mName &
_
" - " & mType & " - " &
mWkSal)
End Sub
Public Function
RtnStr() As String
Return mId & " -
" & mName & _
" - " & mType & " - " &
mWkSal
End Function
Public Function
GetYrSal() As Single
Return mWkSal * 52
End Function
End Class
Project EmpClass1
(better use of Class)
Public Class
frmEmp1
Inherits
System.Windows.Forms.Form
Private Sub
btnGetEmp_Click(ByVal sender As System.Object, ByVal
e As System.EventArgs) Handles
btnGetEmp.Click
Dim aEmp As New Emp
Dim info As String
aEmp.ID = InputBox("Enter id", "Info",
"")
aEmp.Name = InputBox("Enter name",
"Info", "")
aEmp.Type = InputBox("Enter type",
"Info", "")
aEmp.WkSal = InputBox("Enter week sal",
"Info", 0)
info = aEmp.msgStr()
lstEmp.Items.Add(CStr(Emp.InCt)
& " " & info)
End Sub
End Class
Public Class
Emp
Private mId As String
Private mName As String
Private mType As String
Private mWkSal As Single
Private Shared mInCt As Integer = 0
Public Sub
New()
mInCt += 1
End
Sub
Public Property
ID() As String
Get
Return mId
End Get
Set(ByVal Value As String)
mId = Value
End Set
End Property
Public Property
Name() As String
Get
Return mName
End Get
Set(ByVal Value As String)
mName = Value
End Set
End Property
Public Property
Type() As String
Get
Return mType
End Get
Set(ByVal Value As String)
mType = Value
End Set
End Property
Public Property
WkSal() As Single
Get
Return mWkSal
End Get
Set(ByVal Value As Single)
mWkSal = Value
End Set
End Property
Public ReadOnly
Property YrSal() As
Single
Get
If mWkSal > 0 Then
Return (mWkSal *
52)
Else
Return 0
End If
End Get
End Property
Public Shared
ReadOnly Property
InCt() As Integer
Get
Return mInCt
End Get
End Property
Public Function
msgStr() As String
Return ID & " -
" & Name & " - " & _
Type & " - " & FormatCurrency(WkSal)
& _
" - " & FormatCurrency(YrSal)
End Function
End Class