Public Class CellPhoneBillCalculator
Const decTAX_RATE As Decimal = 0.15D
Dim intCallNumber As Integer = 0
Private Sub CellPhoneBillCalculator_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Get today's Date from the system and display it
lblDateToday.Text = FormatDateTime(Now, DateFormat.LongDate)
'Get cureent time from the system and display it
lblTimeToday.Text = FormatDateTime(Now, DateFormat.LongTime)
'Instruct the user to enter call details for each call
GroupBox2.Text = "Call details for Call #" & (intCallNumber + 1)
End Sub
Private Sub btnClearAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClearAll.Click
' This clears all the inputs by user
txtCallDuration.Text = ""
txtTimeZone.Text = ""
lblTax.Text = ""
chkFamilyCall.Checked = False
lblTotalCharge.Text = ""
lblTax.Text = ""
lblTotalCharge.Text = ""
lblCallOneCost.Text = ""
lblCallTwoCost.Text = ""
lblCallThreeCost.Text = ""
End Sub
Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
'Terminates the Application with greeting
MessageBox.Show("Remember to Pay your BILL !!! BYE !!!")
Me.Close()
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim decFirstCall As Decimal
Dim decSecondCall As Decimal
Dim decThirdCall As Decimal
Dim intCallStartTime As Integer
Dim decCallDuration As Decimal
Dim bolErrorFound As Boolean = False
Dim decTimeZoneRate As Decimal
Dim decCurrentCallCost As Decimal
Dim decPreTax As Decimal
Dim decTaxCost As Decimal
Dim decTotal As Decimal
'Display Error Message to Time Zone
If IsNumeric(txtTimeZone.Text) = False Then
MessageBox.Show("Please Enter Time Zone with 24hr Display" & _
ControlChars.CrLf & "6:15AM = 615" & ControlChars.CrLf & _
"6:15PM = 1815", "Error-When Call Conducted", MessageBoxButtons.OK, _
MessageBoxIcon.Warning)
txtTimeZone.Clear()
bolErrorFound = True
ElseIf txtTimeZone.Text > 2459 Then
MessageBox.Show("Please Enter Time Zone with 24hr Display Less Than 2459" & _
ControlChars.CrLf & "6:15AM = 615" & ControlChars.CrLf & _
"6:15PM = 1815", "Error-When Call Conducted", MessageBoxButtons.OK, _
MessageBoxIcon.Warning)
txtTimeZone.Clear()
bolErrorFound = True
ElseIf txtTimeZone.Text < 100 Then
MessageBox.Show("Please Enter Time Zone with 24hr Display Greater than 100" & _
ControlChars.CrLf & "6:15AM = 615" & ControlChars.CrLf & _
"6:15PM = 1815", "Error-When Call Conducted", MessageBoxButtons.OK, _
MessageBoxIcon.Warning)
txtTimeZone.Clear()
bolErrorFound = True
End If
'Display Error Message to Call Duration
If IsNumeric(txtCallDuration.Text) = False Then
MessageBox.Show("Must Enter A Number", "Error-Call Duration", _
MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtCallDuration.Clear()
bolErrorFound = True
ElseIf txtCallDuration.Text <= 1 Then
MessageBox.Show("Must Enter A Number Greater Than 1", "Error-Call Duration", _
MessageBoxButtons.OK, MessageBoxIcon.Warning)
txtCallDuration.Clear()
bolErrorFound = True
End If
If bolErrorFound = False Then
intCallNumber += 1
GroupBox2.Text = "Call details for Call #" & (intCallNumber + 1)
'Determine the rate of the call
intCallStartTime = txtTimeZone.Text
Select Case intCallStartTime
Case 600 To 1759
decTimeZoneRate = 0.14
Case 1800 To 2359
decTimeZoneRate = 0.07
Case Is <= 559
decTimeZoneRate = 0.03
Case 2400 To 2459
decTimeZoneRate = 0.03
End Select
'Call Duration
decCallDuration = CDec(txtCallDuration.Text)
'reset currentcall cost to zero if family plan.
If chkFamilyCall.Checked = True Then
decTimeZoneRate = 0
End If
'Calculates and Saves the Costs for each call
decCurrentCallCost = decCallDuration * decTimeZoneRate
'Stores the Call costs to global variable
If intCallNumber = 1 Then
decFirstCall = decCurrentCallCost
lblCallOneCost.Text = FormatCurrency(decFirstCall)
ElseIf intCallNumber = 2 Then
decSecondCall = decCurrentCallCost
lblCallTwoCost.Text = FormatCurrency(decSecondCall)
ElseIf intCallNumber = 3 Then
decThirdCall = decCurrentCallCost
lblCallThreeCost.Text = FormatCurrency(decThirdCall)
End If
'Clears the boxes for next entry
txtCallDuration.Text = ""
txtTimeZone.Text = ""
chkFamilyCall.Checked = False
End If
'Calculates the total charge for the 3 calls without Tax
If intCallNumber = 3 Then
decPreTax = (decFirstCall + decSecondCall + decThirdCall)
End If
'Calculates and Displays the Tax fee to the three calls
decTaxCost = decPreTax * decTAX_RATE
lblTax.Text = FormatCurrency(decTaxCost)
'Calculates and Displays the Final Charge of the bill
decTotal = decTaxCost + decPreTax
lblTotalCharge.Text = FormatCurrency(decTotal)
End Sub
End Class