Joe's Automotive

parts and tax on parts didn't calculate

Page 1 of 1

2 Replies - 5427 Views - Last Post: 14 December 2010 - 11:19 AM Rate Topic: -----

#1 Alibam  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 13-December 10

Joe's Automotive

Posted 13 December 2010 - 03:30 PM

Hello,
Here is what I have. After debugging it, it works without error. However, the parts amount and tax on parts appear to be zero. Don't know what I am missing or wrong? Please help.


Public Class JoesAutomotive

    ' This application calculates the total order for services, parts and labor
    ' at Joe's Automotive. This application uses several functions to calculate the total cost.
    Const decTAX_RATE As Decimal = 0.06D ' Tax rate on parts 

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        ' This proedure calculates the total of an order.

        Dim decServicesLabor As Decimal ' Holds the labor and services total
        Dim decParts As Decimal ' holds the parts order
        Dim decTax As Decimal ' holds the tax on parts
        Dim decTotal As Decimal ' holds the order total

        decServicesLabor = OilLubeCharges() + FlushCharges() + MiscCharges() + OtherCharges()
        decParts = PartsCost()
        decTax = CalcTax(decParts)
        'decTotal = decServicesLabor + decTax
        decTotal = decServicesLabor + decTax + decParts

        lblServicesLabor.Text = decServicesLabor.ToString("c")
        lblParts.Text = decParts.ToString("c")
        lblTax.Text = decTax.ToString("c")
        lblTotal.Text = decTotal.ToString("c")
    End Sub

    Function PartsIsValid() As Boolean
        ' Declare a value to temporarily hold the parts value.
        Dim decTempValue As Decimal
        If Not Decimal.TryParse(txtParts.Text, decTempValue) Then
            MessageBox.Show("Enter a numeric value for the parts cost.")
            Return False
        End If
        If decTempValue < 0 Then
            MessageBox.Show("Enter a positive value for the parts cost.")
        End If

        ' If we have made it this far, the value is valid, so return true.
        Return True
    End Function
    Function LaborIsValid() As Boolean
        ' Declare a value to temporarily hold the labor value.
        Dim decTempValue2 As Decimal
        If Not Decimal.TryParse(txtLabor.Text, decTempValue2) Then
            MessageBox.Show("Enter a numeric value for the labor cost.")
            Return False
        End If

        If decTempValue2 < 0 Then
            MessageBox.Show("Enter a positive value for the labor cost.")
        End If
        ' If we have made it this far, the value is valid, so return true.
        Return True
    End Function

    Private Sub btnClear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnClear.Click
        ' This procedure resets the controls to default values

        ResetOilLubeCharges()
        ResetFlushCharges()
        ResetMiscCharges()
        OtherCharges()
        ' Clears the text Boxes in the Parts and Labor box
        txtParts.Text = ""
        txtLabor.Text = ""
        ' Clears the boxes in the Summary Box.
        lblServicesLabor.Text = ""
        lblTax.Text = ""
        lblParts.Text = ""
        lblTotal.Text = ""
    End Sub

    Private Sub btnExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnExit.Click
        ' End the application.
        Me.Close()
    End Sub
    Function OilLubeCharges() As Decimal
        'This function returns the cost of the Oil and Lube Charges.

        Dim decCostOfOilLube As Decimal = 0

        If ChkOilChange.Checked = True Then
            decCostOfOilLube += 26D
        End If
        If chkLubeJob.Checked = True Then
            decCostOfOilLube += 18D
        End If
        Return decCostOfOilLube
    End Function
    Function FlushCharges() As Decimal
        ' This function returns the cost of the Flush Charges.

        Dim decCostOfFlush As Decimal = 0

        If ChkRadiatorFlush.Checked = True Then
            decCostOfFlush += 30D
        End If
        If chkTransmissionFlush.Checked = True Then
            decCostOfFlush += 80D
        End If
        Return decCostOfFlush
    End Function
    Function MiscCharges() As Decimal
        ' This function returns the cost of misc.
        Dim decCostOfMisc As Decimal = 0

        If ChkInspection.Checked = True Then
            decCostOfMisc += 15D
        End If
        If chkReplaceMuffler.Checked = True Then
            decCostOfMisc += 100D
        End If
        If chkTireRotation.Checked = True Then
            decCostOfMisc += 20D
        End If
        Return decCostOfMisc
    End Function

    Function PartsCost() As Decimal
        ' This function returns the cost of parts.

    End Function


    Function OtherCharges() As Decimal
        ' This function returns the cost of labor and parts.
        Dim decLarborCharge As Decimal

        decLarborCharge = CDec(txtLabor.Text)

        Return decLarborCharge

    End Function
    Function CalcTax(ByVal decAmount As Decimal) As Decimal
        ' this function receives the parts amount. It calculates and returns the parts tax, based on the parts amount.
        Return decAmount * decTAX_RATE
    End Function


    Private Sub ResetOilLubeCharges()
        ' This procedure resets the Oil and lube selection.
        ChkOilChange.Checked = False
        ChkLubeJob.Checked = False
    End Sub
    Sub ResetFlushCharges()
        ' This procedure resets flush charge selection.
        ChkRadiatorFlush.Checked = False
        ChkTransmissionFlush.Checked = False
    End Sub
    Sub ResetMiscCharges()
        ' This procedure resets all misc charges.
        ChkInspection.Checked = False
        ChkReplaceMuffler.Checked = False
        ChkTireRotation.Checked = False
    End Sub

End Class


Mentor Edit: Please remember to :code:

This post has been edited by AdamSpeight2008: 13 December 2010 - 03:54 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Joe's Automotive

#2 Shadar  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 46
  • View blog
  • Posts: 157
  • Joined: 26-May 09

Re: Joe's Automotive

Posted 14 December 2010 - 11:12 AM

Put a breakpoint on the first executing line and then step through the code (F11). Every time the variable should change hold your mouse over the variable so you can see what the value is. This way you can follow all the code to make sure it is working the way you want.

Another option is while running in debug mode you can highlight a variable, right click on what's highlighted and add a Watch.

This post has been edited by Shadar: 14 December 2010 - 11:12 AM

Was This Post Helpful? 0
  • +
  • -

#3 roadfury  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 7
  • View blog
  • Posts: 52
  • Joined: 05-February 07

Re: Joe's Automotive

Posted 14 December 2010 - 11:19 AM

You aren't returning a value in your PartsCost() function.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1