All pastes #924382 Raw Edit

PJ2 CS5

public text v1 · immutable
·published 2008-03-01 08:11 UTC
rendered paste body
Public Class CellPhoneBillCalculator
    Const decTAX_RATE As Decimal = 0.15D
    Dim intCallNumber As Integer = 1
    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

    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 = ""
        lblPreTax.Text = ""
        lblTax.Text = ""
        chkFamilyCall.Checked = False
        lblTotalCharge.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 decCurrentCallCost As Decimal
        Dim decCallDuration As Decimal
        Dim bolErrorFound As Boolean = False
        Dim decPreTax As Decimal
        Dim decTaxCost As Decimal
        Dim decTotalCharge As Decimal
        Dim decTimeZoneRate 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

            '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 each local variable
            If intCallNumber = 1 Then
                decFirstCall = decCurrentCallCost
            ElseIf intCallNumber = 2 Then
                decSecondCall = decCurrentCallCost
            ElseIf intCallNumber = 3 Then
                decThirdCall = decCurrentCallCost
            End If

            'Clears the boxes for next entry
            txtCallDuration.Text = ""
            txtTimeZone.Text = ""
            chkFamilyCall.Checked = False
        End If

        'Calculates and Display the total charge for the 3 calls without Tax
        decPreTax = decFirstCall + decSecondCall + decThirdCall
        lblPreTax.Text = FormatCurrency(decPreTax)

        'Calculates and Displays the Tax fee to the three calls
        decTaxCost = CDec(lblPreTax.Text) * decTAX_RATE
        lblTax.Text = FormatCurrency(decTaxCost)

        'Calculates and Displays the Final Charge of the bill
        decTotalCharge = CDec(lblTax.Text) + CDec(lblPreTax.Text)
        lblTotalCharge.Text = FormatCurrency(decTotalCharge)

    End Sub

End Class