Click here to Skip to main content
15,881,797 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
Hi. I am working on an assignment for school and am having issues with getting the program to perform calculations. I don't get any errors on debug, and I have no idea where to start. I can post code, but it is rather long...so I will wait to see if anyone is available to try to help me before posting it.

I think this snipet is my issue, but I don't know for sure..

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
Posted
Updated 30-May-11 15:00pm
v5
Comments
Manfred Rudolf Bihy 30-May-11 19:57pm    
Admitting that this a school assignment is a start. Usually we don't do help on this basis, but it you'd want our help it would be of utmost importance to tell us what you are trying to achieve and which part of your work is actually failing.

Just dumping a piece of code on us is not going to fetch you any help nor sympathy.
midgetchris 30-May-11 20:11pm    
Thanks for a reply....I understand that the community might be reluctant to help since it is a school assignment. I am trying to get a windows application to accept input from the user for the current fuel price, miles traveled per year, the years of planned ownership of the 2 vehicles, and the MPG for each vehicle. Then when the calculate button is pressed, it would calculate the suv gas cost, the compact car gas cost, and the price difference between the two. When I press my calculate button it only shows $0.00 for the suv gas cost, car gas cost, and difference.
midgetchris 30-May-11 20:45pm    
Well since you're the only one who has responded, do you think it would be easier if i just scrapped the whole thing that I have and start over? Because I have about 270 lines of code and I can't figure out where I went wrong.
Firo Atrum Ventus 30-May-11 22:04pm    
Let me tell you what's wrong with your code. You don't even calculate anything, you just validate everything and show the results(since you don't calculate anything, it would be 0). Stop copying from your teacher's note and start experimenting!
Sergey Alexandrovich Kryukov 30-May-11 22:38pm    
To start with, tag your question! Add VB.NET. Is UI involved? Tag the library: WPF, Forms, what?!
--SA

1 solution

Firo, Thank you for sort-of getting me on the right path, but I could have done without the assumption of copying from teacher's note. I could have completed this project with no issue without all the functions and WAY less coding, but the instructions for this assignment required those functions. I've been playing with basic Visual Basic for over 5 years. This might be my first question post, but I have learned a lot from many people here in the last 5 years, and all just by reading other peoples questions and the answers they got.

I placed the function for calculations in the wrong place, below this snipet instead of above it.I took out all my code. Then put my calculations in. Then ran debug. Then I pasted one function at a time back in, rearranging my calculations as needed, until I found all of my errors. 3 to be exact, one of which was with the posted code. One was related to inadvertently partially wording in C++, that Visual Studio 2010 didn't catch. And the last was another instance of improper calling/return for a function.

Problem Solved.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900