Private Sub btnCompareLifeOfVehicleCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCompareLifeOfVehicleCost.Click 'This button event handler determines the SUV Gas cost, 'Compact Gas Cost, and the difference in the cost Dim intYearsOwned As Integer Dim blnNumberInFuelCostIsValid As Boolean = False Dim blnMilesTraveledPerYearIsValid As Boolean = False Dim blnYearsIsSelected As Boolean = False Dim strNumberSelected As String = "" Dim blnSUVMPGIsValid As Boolean = False Dim blnCompactCarMpgIsValid As Boolean = False Dim decSUVcost As Decimal Dim decCompactcost As Decimal Dim decDifference As Decimal 'Set focus on fuel cost per gallon text box txtFuelCostPerGallon.Focus() 'Call a function to ensure the number for fuel cost is valid blnNumberInFuelCostIsValid = ValidateNumberInFuelCost() 'Call a function to ensure the miles traveled per year is valid blnMilesTraveledPerYearIsValid = ValidateMilesTraveledPerYear() 'Call a function to ensure the number of years was selected intYearsOwned = ValidateYearsSelection(blnYearsIsSelected) 'Call a function to ensure the SUV MPG is valid blnSUVMPGIsValid = ValidateSUVMPG() 'Call a function to ensure the Compact Car MPG is valid blnCompactCarMpgIsValid = ValidateCompactCarMPG() 'If fuel cost per gallon, miles traveled per year, years of ownership, SUV MPG and Compact Car 'MPG are all valid, calculate the SUV Gas cost, Compact Car gas cost, and the difference in cost If (blnNumberInFuelCostIsValid And blnMilesTraveledPerYearIsValid And blnSUVMPGIsValid And blnCompactCarMpgIsValid And blnYearsIsSelected) Then 'Make items visible in the window lblSUVGasCost.Visible = True lblCompactGasCost.Visible = True lblDifferenceInCost.Visible = True 'Display the SUV gas cost, compact car gas cost, and difference in Cost lblSUVGasCost.Text = "SUV Gas Cost: " & decSUVcost.ToString("C") lblCompactGasCost.Text = "Compact Gas Cost: " & decCompactcost.ToString("C") decDifference = decSUVcost - decCompactcost lblDifferenceInCost.Text = "Difference in Cost: " & decDifference.ToString("C") End If End Sub
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)