2 Replies - 519 Views - Last Post: 02 October 2012 - 09:22 AM Rate Topic: -----

#1 compucrazy  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 30-September 12

Wrong calculations in VB...need help!

Posted 01 October 2012 - 04:17 PM

Everything with the program works but the parts and supplies cost should equal 157.50 and the total cost would equal 577.50. My calculations are wrong but I am not sure what to do to get that to put out the right number.

Also I have to include a service date that the user picks upon running the program then I have to display an invoice date (or today's date). I know I have to use the DateTime function, but I have no idea how to use it. Please help!

 Dim Customer As String
    Dim Phone As String
    Dim Hours As Double
    Dim Parts As Double
   
    ''Validate user input information''
    Private Sub btnBill_Click(sender As System.Object, e As System.EventArgs) Handles btnBill.Click

        Customer = txtCustomer.Text
        Phone = mtbPhone.Text

        Double.TryParse(txtHours.Text, Hours)
        Double.TryParse(txtParts.Text, Parts)

        If Customer.Length < 0 Then
            MessageBox.Show("Please enter customer information.")
        End If

        If Phone = "" Then
            MessageBox.Show("Please enter phone number.")
        End If

        If Not Double.TryParse(txtHours.Text, Hours) Then
            MessageBox.Show("Please enter labor hours.")
        End If

        If Not Double.TryParse(txtParts.Text, Parts) Then
            MessageBox.Show("Please enter parts and supplies.")
        End If

        ''Perform calculations

        Dim Total_Cost As Double
        Dim Labor_Cost As Double
        Dim Parts_Cost As Double

        Parts_Cost = (Parts * 5 / 100)
        Labor_Cost = (Hours * 35)
        Total_Cost = (Hours + Parts)


        Customer = txtCustomer.Text
        Phone = mtbPhone.Text

        lstBill.Items.Clear()
        lstBill.Items.Add("Customer: " & vbTab & Customer.ToUpper)
        lstBill.Items.Add("Phone: " & vbTab & vbTab & Phone)
        lstBill.Items.Add("Labor Cost: " & vbTab & FormatCurrency(Labor_Cost))
        lstBill.Items.Add("Parts Cost: " & vbTab & FormatCurrency(Parts_Cost))
        lstBill.Items.Add("Total Cost: " & vbTab & FormatCurrency(Total_Cost))

        
    End Sub

End Class

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Replies To: Wrong calculations in VB...need help!

#2 AdamSpeight2008  Icon User is offline

  • MrCupOfT
  • member icon


Reputation: 2268
  • View blog
  • Posts: 9,482
  • Joined: 29-May 08

Re: Wrong calculations in VB...need help!

Posted 01 October 2012 - 04:36 PM

Start by learning and using some debugging skills
Was This Post Helpful? 1
  • +
  • -

#3 torind_2000  Icon User is offline

  • D.I.C Regular
  • member icon

Reputation: 57
  • View blog
  • Posts: 292
  • Joined: 22-August 11

Re: Wrong calculations in VB...need help!

Posted 02 October 2012 - 09:22 AM

View Postcompucrazy, on 01 October 2012 - 07:17 PM, said:

        
' Perform calculations
        ' start here with the debugging skills you learned from Adams response.
        Dim Total_Cost As Double
        Dim Labor_Cost As Double
        Dim Parts_Cost As Double

        Parts_Cost = (Parts * 5 / 100)
        Labor_Cost = (Hours * 35)
        ' whats the point of doing the math above,
        ' if you don't use the results to do the math below
        Total_Cost = (Hours + Parts)

        ' why do you do this twice?
        Customer = txtCustomer.Text
        Phone = mtbPhone.Text

End Class


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1