0

I am testing my program "Pats Auto Repair shop" that includes the mainform with menustrips for file, process and help, Splash form, About, Job information form and summary form. The process has two subs, job information with a separator for "summary", and summary form.

I written all coding solutions for the 3 forms (Main, Job, Summary). When pressing the calculate button on the job form I get a data error. Can someone take a look and see where I went wrong?

3
Contributors
2
Replies
33
Views
11 Months
Discussion Span
Last Post by tinstaafl
0

In the event handler for the CalculateButton.Click event you're parsing raw data without checking if it's valid. you will find much better success by initializing the decimal variables to 0 and parsing the textboxes with TryParse. If it succeeds the variable will have a new value. If not it will have 0. Also since your data is now more robust I would suggest that you can do away with the Try block, which isn't really being used properly in the first place:

    Dim PartsDecimal As Decimal = 0
    Dim SubTotalDecimal As Decimal = 0
    Dim SalesTaxRateDecimal As Decimal = 0
    Dim TotalDecimal As Decimal = 0
    Dim LaborTotalDecimal As Decimal = 0
    Dim LaborHoursDecimal As Decimal = 0
    Dim PartsAmtDecimal As Decimal = 0

    'Calculate the extended price and add to job total.'
    Decimal.TryParse(PartsTextBox.Text, PartsDecimal)
    Decimal.TryParse(PartsAmtTextBox.Text, PartsAmtDecimal)
    Decimal.TryParse(LaborHoursTextBox.Text, LaborHoursDecimal)
    Decimal.TryParse(HoursOfLaborTextBox.Text, LaborTotalDecimal)
    SubTotalDecimal = PartsDecimal + LABOR_COST_Decimal * HoursOfLaborDecimal
    TotalDecimal = SubTotalDecimal + (SALES_TAX_RATE_Decimal * SubTotalDecimal)

Edited by tinstaafl

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.