Events/collections etc

 

Invraise

 

Public Class frmInv

Inherits System.Windows.Forms.Form

Private WithEvents invenIns As ClassInv

Dim wkMsg As String

 

Private Sub btnRecv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecv.Click

Dim intOnHand As Integer

Dim intOnOrder As Integer

Dim intReceive As Integer

Dim intUpdtOnHand As Integer

Dim intUpdtOnOrder As Integer

intOnHand = CStr(txtOnHand.Text)

intOnOrder = CStr(txtOnOrder.Text)

intReceive = CStr(txtReceive.Text)

invenIns = New ClassInv(intOnHand, intOnOrder)

invenIns.ReceiveInv(intReceive)

intUpdtOnHand = invenIns.OnHand 'using Get of OnHand

intUpdtOnOrder = invenIns.OnOrder 'using Get of OnOrder

txtUpdtOnHand.Text = CStr(intUpdtOnHand)

txtUpdtOnOrder.Text = CStr(intUpdtOnOrder)

End Sub

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

End

End Sub

Private Sub invenIns_NeedToOrder() Handles invenIns.NeedToOrder

wkMsg = "Quantity to low"

MsgBox(wkMsg, MsgBoxStyle.Exclamation, "Need to Order")

End Sub

Private Sub invenIns_NothingOnOrder() Handles invenIns.NothingOnOrder

wkMsg = "Nothing on order"

MsgBox(wkMsg, MsgBoxStyle.Information, "No Order Pending")

End Sub

End Class

 

Public Class ClassInv

Public Event NeedToOrder()

Public Event NothingOnOrder()

Private m_onhand As Integer

Private m_onorder As Integer

Public Sub New(ByVal s_onhand As Integer, ByVal s_onorder As Integer)

OnHand = s_onhand 'invokes OnHand Set accessor

OnOrder = s_onorder 'invokes OnOrder Set accessor

End Sub

Public Property OnHand() As Integer

Get

Return m_onhand

End Get

Set(ByVal Value As Integer)

m_onhand = Value

End Set

End Property

Public Property OnOrder() As Integer

Get

Return m_onorder

End Get

Set(ByVal Value As Integer)

m_onorder = Value

End Set

End Property

Sub ReceiveInv(ByVal s_receive As Integer)

m_onhand = m_onhand + s_receive

m_onorder = m_onorder - s_receive

If m_onhand < 50 And m_onorder < 50 Then

RaiseEvent NeedToOrder()

End If

If m_onorder = 0 Or m_onorder < 0 Then

RaiseEvent NothingOnOrder()

End If

End Sub

End Class

 

Invraise2

 

Public Class frmInv

Inherits System.Windows.Forms.Form

Private WithEvents invenIns As ClassInv

Dim wkMsg As String

 

Private Sub btnRecv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecv.Click

Dim intOnHand As Integer

Dim intOnOrder As Integer

Dim intReceive As Integer

Dim intUpdtOnHand As Integer

Dim intUpdtOnOrder As Integer

intOnHand = CStr(txtOnHand.Text)

intOnOrder = CStr(txtOnOrder.Text)

intReceive = CStr(txtReceive.Text)

invenIns = New ClassInv(intOnHand, intOnOrder)

invenIns.ReceiveInv(intReceive)

intUpdtOnHand = invenIns.OnHand 'using Get of OnHand

intUpdtOnOrder = invenIns.OnOrder 'using Get of OnOrder

txtUpdtOnHand.Text = CStr(intUpdtOnHand)

txtUpdtOnOrder.Text = CStr(intUpdtOnOrder)

End Sub

 

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

End

End Sub

Private Sub invenIns_NeedToOrder(ByVal e_onhand As Integer, ByVal e_onorder As Integer) _

Handles invenIns.NeedToOrder

wkMsg = "Quantity to low " & CStr(e_onorder) & " " & CStr(e_onhand)

MsgBox(wkMsg, MsgBoxStyle.Exclamation, "Need to Order")

End Sub

Private Sub invenIns_NothingOnOrder(ByVal e_onorder As Integer) _

Handles invenIns.NothingOnOrder

wkMsg = "Nothing on order " & CStr(e_onorder)

MsgBox(wkMsg, MsgBoxStyle.Information, "No Order Pending")

End Sub

End Class

 

Public Class ClassInv

Private m_onhand As Integer

Private m_onorder As Integer

Public Event NeedToOrder(ByVal m_onhand As Integer, ByVal m_onorder As Integer)

Public Event NothingOnOrder(ByVal m_onorder As Integer)

 

Public Sub New(ByVal s_onhand As Integer, ByVal s_onorder As Integer)

OnHand = s_onhand 'invokes OnHand Set accessor

OnOrder = s_onorder 'invokes OnOrder Set accessor

End Sub

Public Property OnHand() As Integer

Get

Return m_onhand

End Get

Set(ByVal Value As Integer)

m_onhand = Value

End Set

End Property

Public Property OnOrder() As Integer

Get

Return m_onorder

End Get

Set(ByVal Value As Integer)

m_onorder = Value

End Set

End Property

Sub ReceiveInv(ByVal s_receive As Integer)

'Dim re_onhand As Integer

'Dim re_onorder As Integer

m_onhand = m_onhand + s_receive

m_onorder = m_onorder - s_receive

If m_onhand < 50 And m_onorder < 50 Then

're_onhand = m_onhand

're_onorder = m_onorder

'RaiseEvent NeedToOrder(re_onhand, re_onorder)

RaiseEvent NeedToOrder(m_onhand, m_onorder)

End If

If m_onorder = 0 Or m_onorder < 0 Then

're_onorder = m_onorder

'RaiseEvent NothingOnOrder(re_onorder)

RaiseEvent NothingOnOrder(m_onorder)

End If

End Sub

End Class

 

 

 

Invraise2a

 

Public Class frmInv

Inherits System.Windows.Forms.Form

Private WithEvents invenIns As ClassInv

Dim wkMsg As String

 

Private Sub btnRecv_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRecv.Click

Dim intOnHand As Integer

Dim intOnOrder As Integer

Dim intReceive As Integer

Dim intUpdtOnHand As Integer

Dim intUpdtOnOrder As Integer

intOnHand = CStr(txtOnHand.Text)

intOnOrder = CStr(txtOnOrder.Text)

intReceive = CStr(txtReceive.Text)

invenIns = New ClassInv(intOnHand, intOnOrder)

invenIns.ReceiveInv(intReceive)

intUpdtOnHand = invenIns.OnHand 'using Get of OnHand

intUpdtOnOrder = invenIns.OnOrder 'using Get of OnOrder

txtUpdtOnHand.Text = CStr(intUpdtOnHand)

txtUpdtOnOrder.Text = CStr(intUpdtOnOrder)

End Sub

 

Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click

End

End Sub

Private Sub invenIns_HandleEvents(ByVal e_onorder As Integer, ByVal e_Msg As String) _

Handles invenIns.NeedToOrder, invenIns.NothingOnOrder

wkMsg = e_Msg & " " & CStr(e_onorder)

MsgBox(wkMsg, MsgBoxStyle.Exclamation, "Need to Order")

End Sub

End Class

 

Public Class ClassInv

Private m_onhand As Integer

Private m_onorder As Integer

Public Event NeedToOrder(ByVal m_onorder As Integer, ByVal a_Msg As String)

Public Event NothingOnOrder(ByVal m_onorder As Integer, ByVal a_Msg As String)

 

Public Sub New(ByVal s_onhand As Integer, ByVal s_onorder As Integer)

OnHand = s_onhand 'invokes OnHand Set accessor

OnOrder = s_onorder 'invokes OnOrder Set accessor

End Sub

Public Property OnHand() As Integer

Get

Return m_onhand

End Get

Set(ByVal Value As Integer)

m_onhand = Value

End Set

End Property

Public Property OnOrder() As Integer

Get

Return m_onorder

End Get

Set(ByVal Value As Integer)

m_onorder = Value

End Set

End Property

Sub ReceiveInv(ByVal s_receive As Integer)

Dim a_Msg As String

m_onhand = m_onhand + s_receive

m_onorder = m_onorder - s_receive

If m_onhand < 50 And m_onorder < 50 Then

a_Msg = "Need to order"

RaiseEvent NeedToOrder(m_onorder, a_Msg)

End If

If m_onorder = 0 Or m_onorder < 0 Then

a_Msg = "Nothing on order"

RaiseEvent NothingOnOrder(m_onorder, a_Msg)

End If

End Sub

End Class

 

CalcStuGradeRO

 

Public Class frmStuGrade

Inherits System.Windows.Forms.Form

Dim objStuGrade As ClassStuGrade

 

Private Sub btnCalcFinalGrade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcFinalGrade.Click

Dim intGrade1 As Integer

Dim intGrade2 As Integer

Dim intGrade3 As Integer

Dim intAverage As Integer

Dim strName As String

strName = InputBox("Student Name", "Enter")

intGrade1 = CInt(txtGrade1.Text)

intGrade2 = CInt(txtGrade2.Text)

intGrade3 = CInt(txtGrade3.Text)

objStuGrade = New ClassStuGrade(strName)

objStuGrade.CalcFinalGrade(intGrade1, intGrade2, intGrade3)

intAverage = objStuGrade.Average

txtAverage.Text = CStr(intAverage)

txtFinalGrade.Text = objStuGrade.FinalGrade

txtName.Text = objStuGrade.StuName

End Sub

End Class

 

Public Class ClassStuGrade

Private m_stuname As String

Private m_average As Integer

Private m_finalgrade As String

 

Public Sub New(ByVal s_stuname As String)

StuName = s_stuname 'invokes StuName Set accessor

End Sub

Public Property StuName() As String

Get

Return m_stuname

End Get

Set(ByVal Value As String)

m_stuname = Value

End Set

End Property

Public ReadOnly Property Average() As Integer

Get

Return m_average

End Get

End Property

Public ReadOnly Property FinalGrade() As String

Get

Return m_finalgrade

End Get

End Property

Sub CalcFinalGrade(ByVal s_grade1 As Integer, ByVal s_grade2 As Integer, ByVal s_grade3 As Integer)

m_average = CInt((s_grade1 + s_grade2 + s_grade3) / 3)

If m_average >= 90 Then

m_finalgrade = "A"

Else

If m_average >= 80 Then

m_finalgrade = "B"

Else

If m_average >= 70 Then

m_finalgrade = "C"

Else

If m_average >= 60 Then

m_finalgrade = "D"

Else

m_finalgrade = "F"

End If

End If

End If

End If

End Sub

End Class

 

 

CalcStuGradeForm

 

Public Class frmStuGrade

Inherits System.Windows.Forms.Form

Dim objStuGrade As ClassStuGrade

 

Private Sub btnCalcFinalGrade_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcFinalGrade.Click

Dim intGrade1 As Integer

Dim intGrade2 As Integer

Dim intGrade3 As Integer

Dim intAverage As Integer

Dim strFinalGrade As String

Dim strName As String

strName = InputBox("Student Name", "Enter")

intGrade1 = CInt(txtGrade1.Text)

intGrade2 = CInt(txtGrade2.Text)

intGrade3 = CInt(txtGrade3.Text)

intAverage = CInt((intGrade1 + intGrade2 + intGrade3) / 3)

If intAverage >= 90 Then

strFinalGrade = "A"

Else

If intAverage >= 80 Then

strFinalGrade = "B"

Else

If intAverage >= 70 Then

strFinalGrade = "C"

Else

If intAverage >= 60 Then

strFinalGrade = "D"

Else

strFinalGrade = "F"

End If

End If

End If

End If

objStuGrade = New ClassStuGrade(strName, intAverage, strFinalGrade)

intAverage = objStuGrade.Average

txtAverage.Text = CStr(intAverage)

txtFinalGrade.Text = objStuGrade.FinalGrade

txtName.Text = objStuGrade.StuName

End Sub

End Class

 

Public Class ClassStuGrade

Private m_stuname As String

Private m_average As Integer

Private m_finalgrade As String

 

Public Sub New(ByVal s_stuname As String, ByVal s_average As Integer, ByVal s_finalgrade As String)

StuName = s_stuname 'invokes StuName Set accessor

Average = s_average

FinalGrade = s_finalgrade

End Sub

Public Property StuName() As String

Get

Return m_stuname

End Get

Set(ByVal Value As String)

m_stuname = Value

End Set

End Property

Public Property Average() As Integer

Get

Return m_average

End Get

Set(ByVal Value As Integer)

m_average = Value

End Set

End Property

Public Property FinalGrade() As String

Get

Return m_finalgrade

End Get

Set(ByVal Value As String)

m_finalgrade = Value

End Set

End Property

End Class

 

PhoneLog

 

Public Class frmPhoneLog

Inherits System.Windows.Forms.Form

Private phoneCall As ClassPhone

Dim PhoneCalls As New Collection

Dim s_LogNo As Integer

 

Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click

If txtCaller.Text <> "" Then

s_LogNo = PhoneCalls.Count + 1

txtLogNo.Enabled = True

txtLogNo.Text = CStr(s_LogNo)

txtTimeCall.Enabled = True

txtTimeCall.Text = CStr(Date.Now)

phoneCall = New ClassPhone(s_LogNo)

phoneCall.Caller = txtCaller.Text

phoneCall.CallTime = CDate(txtTimeCall.Text)

phoneCall.Subject = txtSubject.Text

PhoneCalls.Add(phoneCall, CStr(phoneCall.LogNo))

txtLogNo.Enabled = False

txtTimeCall.Enabled = False

txtCaller.Enabled = False

txtSubject.Enabled = False

btnNewCall.Focus()

Else

txtCaller.Focus()

End If

End Sub

 

Private Sub btnNewCall_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewCall.Click

txtLogNo.Enabled = True

txtLogNo.Text = ""

txtLogNo.Enabled = False

txtTimeCall.Enabled = True

txtTimeCall.Text = ""

txtTimeCall.Enabled = False

txtCaller.Enabled = True

txtCaller.Text = ""

txtSubject.Enabled = True

txtSubject.Text = ""

txtCaller.Focus()

End Sub

 

Private Sub btnListCalls_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnListCalls.Click

lstCalls.Items.Clear()

For Each phoneCall In PhoneCalls

Dim phoneline As String

phoneline = CStr(phoneCall.LogNo) & " " _

& CStr(phoneCall.CallTime) & " " _

& phoneCall.Caller & " " _

& phoneCall.Subject

lstCalls.Items.Add(phoneline)

lstCalls.Refresh()

Next phoneCall

btnNewCall.Focus()

End Sub

 

End Class

Public Class ClassPhone

Private m_LogNo As Integer

Private m_TimeCall As DateTime

Private m_Caller As String

Private m_Subject As String

 

Public Sub New(ByVal s_LogNo As Integer)

m_LogNo = s_LogNo

End Sub

 

Public ReadOnly Property LogNo() As Integer

Get

Return m_LogNo

End Get

 

End Property

 

Public Property CallTime() As DateTime

Get

Return m_TimeCall

End Get

Set(ByVal s_TimeCall As DateTime)

m_TimeCall = s_TimeCall

End Set

End Property

 

Public Property Caller() As String

Get

Return m_Caller

End Get

Set(ByVal s_Caller As String)

m_Caller = s_Caller

End Set

End Property

 

Public Property Subject() As String

Get

Return m_Subject

End Get

Set(ByVal s_Subject As String)

m_Subject = s_Subject

End Set

End Property

End Class

 

PhoneLog1

 

Public Class frmPhoneLog

Inherits System.Windows.Forms.Form

Private phoneCall As ClassPhone

Dim PhoneCalls As New Collection

Dim s_LogNo As Integer

 

Private Sub btnLog_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLog.Click

If txtCaller.Text <> "" Then

s_LogNo = PhoneCalls.Count + 1

txtLogNo.Enabled = True

txtLogNo.Text = CStr(s_LogNo)

txtTimeCall.Enabled = True

txtTimeCall.Text = CStr(Date.Now)

phoneCall = New ClassPhone(s_LogNo, txtCaller.Text, CDate(txtTimeCall.Text), _

txtSubject.Text)

'phoneCall.Caller = txtCaller.Text

'phoneCall.CallTime = CDate(txtTimeCall.Text)

'phoneCall.Subject = txtSubject.Text

PhoneCalls.Add(phoneCall, CStr(phoneCall.LogNo))

txtLogNo.Enabled = False

txtTimeCall.Enabled = False

txtCaller.Enabled = False

txtSubject.Enabled = False

btnNewCall.Focus()

Else

txtCaller.Focus()

End If

End Sub

 

Private Sub btnNewCall_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnNewCall.Click

txtLogNo.Enabled = True

txtLogNo.Text = ""

txtLogNo.Enabled = False

txtTimeCall.Enabled = True

txtTimeCall.Text = ""

txtTimeCall.Enabled = False

txtCaller.Enabled = True

txtCaller.Text = ""

txtSubject.Enabled = True

txtSubject.Text = ""

txtCaller.Focus()

End Sub

 

Private Sub btnListCalls_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnListCalls.Click

lstCalls.Items.Clear()

For Each phoneCall In PhoneCalls

Dim phoneline As String

phoneline = CStr(phoneCall.LogNo) & " " _

& CStr(phoneCall.CallTime) & " " _

& phoneCall.Caller & " " _

& phoneCall.Subject

lstCalls.Items.Add(phoneline)

'lstCalls.Refresh()

Next phoneCall

btnNewCall.Focus()

End Sub

 

End Class

 

Public Class ClassPhone

Private m_LogNo As Integer

Private m_TimeCall As DateTime

Private m_Caller As String

Private m_Subject As String

 

Public Sub New(ByVal s_LogNo As Integer, ByVal s_Caller As String, _

ByVal s_TimeCall As Date, ByVal s_Subject As String)

m_LogNo = s_LogNo

Caller = s_Caller

CallTime = s_TimeCall

Subject = s_Subject

End Sub

 

Public ReadOnly Property LogNo() As Integer

Get

Return m_LogNo

End Get

 

End Property

 

Public Property CallTime() As DateTime

Get

Return m_TimeCall

End Get

Set(ByVal s_TimeCall As DateTime)

m_TimeCall = s_TimeCall

End Set

End Property

 

Public Property Caller() As String

Get

Return m_Caller

End Get

Set(ByVal s_Caller As String)

m_Caller = s_Caller

End Set

End Property

 

Public Property Subject() As String

Get

Return m_Subject

End Get

Set(ByVal s_Subject As String)

m_Subject = s_Subject

End Set

End Property

End Class