Option Strict On Option Explicit On Public Class Form1 'James Blakeman 'May 7, 2009 'Application takes all calculations of user's inputed data. 'Constants Const dblMEALS As Double = 37 Const dblMIlES As Double = 0.27 Const dblPARKING As Double = 10 Const dblTAXI As Double = 20 Const dblLODGE As Double = 95 Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click 'Dim statements Dim dblTotal As Double Dim dblSaved As Double Dim dblReimbursed As Double Dim dblUnallowed As Double dblTotal = CalcMeals() + CalcLodging() + CalcParkingFees() + CalcTaxiFees() + CalcMileage() lblCustomerTotal.Text = FormatCurrency(dblTotal.ToString) dblReimbursed = CalcTotalReimbursement() lblAllowed.Text = FormatCurrency(dblReimbursed.ToString) dblSaved = CalcSaved() lblSaved.Text = FormatCurrency(dblSaved.ToString) dblUnallowed = CalcUnallowed() lblOverage.Text = FormatCurrency(dblUnallowed.ToString) End Sub Function CalcMeals() As Double 'Dim Statement Dim dblTotalMeal As Double If Not txtDaysTrip.Text = String.Empty Then If Double.TryParse(txtDaysTrip.Text, dblTotalMeal) Then dblTotalMeal = dblMEALS * CDbl(txtDaysTrip.Text) End If End If Return (dblTotalMeal) End Function Function CalcMileage() As Double 'Dim Statement Dim dblTotalMiles As Double If Not txtMiles.Text = String.Empty Then If Double.TryParse(txtMiles.Text, dblTotalMiles) Then dblTotalMiles = dblMIlES * CDbl(txtMiles.Text) End If End If Return (dblTotalMiles) End Function Function CalcParkingFees() As Double 'Dim Statement Dim dblParkingTotal As Double If Not txtParking.Text = String.Empty Then If Double.TryParse(txtParking.Text, dblParkingTotal) Then dblParkingTotal = dblPARKING * CDbl(txtDaysTrip.Text) End If End If Return (dblParkingTotal) End Function Function CalcTaxiFees() As Double 'Dim Statement Dim dblTaxiTotal As Double If Not txtTaxi.Text = String.Empty Then If Double.TryParse(txtTaxi.Text, dblTaxiTotal) Then dblTaxiTotal = dblTAXI * CDbl(txtDaysTrip.Text) End If End If Return (dblTaxiTotal) End Function Function CalcLodging() As Double 'Dim Statement Dim dblLodgeTotal As Double If Not txtLodge.Text = String.Empty Then If Double.TryParse(txtLodge.Text, dblLodgeTotal) Then dblLodgeTotal = dblLODGE * CDbl(txtLodge.Text) End If End If Return (dblLodgeTotal) End Function Function CalcTotalReimbursement() As Double 'Dim Statement Dim dblTotalReimbursed As Double If Not txtDaysTrip.Text = String.Empty Then If Double.TryParse(txtDaysTrip.Text, dblTotalReimbursed) Then If (CalcMeals() / CDbl(txtDaysTrip.Text)) < dblMEALS Then dblTotalReimbursed += CalcMeals() Else dblTotalReimbursed += dblMEALS * CDbl(txtDaysTrip.Text) End If End If End If If Not txtMiles.Text = String.Empty Then If Double.TryParse(txtMiles.Text, dblTotalReimbursed) Then If (CalcMileage() / CDbl(txtMiles.Text)) < dblMIlES Then dblTotalReimbursed += CalcMileage() Else dblTotalReimbursed += dblMIlES * CDbl(txtMiles.Text) End If End If End If If Not txtParking.Text = String.Empty Then If Double.TryParse(txtParking.Text, dblTotalReimbursed) Then If (CalcParkingFees() / CDbl(txtParking.Text)) < dblPARKING Then dblTotalReimbursed += CalcParkingFees() Else dblTotalReimbursed += dblPARKING * CDbl(txtParking.Text) End If End If End If If Not txtTaxi.Text = String.Empty Then If Double.TryParse(txtTaxi.Text, dblTotalReimbursed) Then If (CalcTaxiFees() / CDbl(txtTaxi.Text)) < dblTAXI Then dblTotalReimbursed += CalcTaxiFees() Else dblTotalReimbursed += dblTAXI * CDbl(txtTaxi.Text) End If End If End If If Not txtLodge.Text = String.Empty Then If Double.TryParse(txtLodge.Text, dblTotalReimbursed) Then If (CalcLodging() / CDbl(txtDaysTrip.Text)) < dblLODGE Then dblTotalReimbursed += CalcLodging() Else dblTotalReimbursed += dblLODGE * CDbl(txtDaysTrip.Text) End If End If End If Return (dblTotalReimbursed) End Function Function CalcUnallowed() As Double 'Dim Statement Dim dblUnallowed As Double If Not txtDaysTrip.Text = String.Empty Then If Double.TryParse(txtDaysTrip.Text, dblUnallowed) Then If (CalcMeals() / CDbl(txtDaysTrip.Text)) > dblMEALS Then dblUnallowed += CalcMeals() - (dblMEALS * CDbl(txtDaysTrip.Text)) End If End If End If If Not txtMiles.Text = String.Empty Then If Double.TryParse(txtMiles.Text, dblUnallowed) Then If (CalcMileage() / CDbl(txtMiles.Text)) > dblMIlES Then dblUnallowed += CalcMileage() - (dblMIlES * CDbl(txtMiles.Text)) End If End If End If If Not txtParking.Text = String.Empty Then If Double.TryParse(txtParking.Text, dblUnallowed) Then If (CalcParkingFees() / CDbl(txtParking.Text)) > dblPARKING Then dblUnallowed += CalcParkingFees() - (dblPARKING * CDbl(txtParking.Text)) End If End If End If If Not txtTaxi.Text = String.Empty Then If Double.TryParse(txtTaxi.Text, dblUnallowed) Then If (CalcTaxiFees() / CDbl(txtTaxi.Text)) > dblTAXI Then dblUnallowed += CalcTaxiFees() - (dblTAXI * CDbl(txtTaxi.Text)) End If End If End If If Not txtLodge.Text = String.Empty Then If Double.TryParse(txtLodge.Text, dblUnallowed) Then If (CalcLodging() / CDbl(txtLodge.Text)) > dblLODGE Then dblUnallowed += CalcLodging() - (dblLODGE * CDbl(txtDaysTrip.Text)) End If End If End If Return dblUnallowed End Function Function CalcSaved() As Double 'Dim Statement Dim dblSaved As Double If Not txtDaysTrip.Text = String.Empty Then If Double.TryParse(txtDaysTrip.Text, dblSaved) Then If (dblMEALS * CDbl(txtDaysTrip.Text)) - CalcMeals() > 0 Then dblSaved += (dblMEALS * CDbl(txtDaysTrip.Text)) - CalcMeals() End If End If End If If Not txtMiles.Text = String.Empty Then If Double.TryParse(txtMiles.Text, dblSaved) Then If (dblMIlES * CDbl(txtMiles.Text)) - CalcMileage() > 0 Then dblSaved += (dblMIlES * CDbl(txtMiles.Text)) - CalcMileage() End If End If End If If Not txtParking.Text = String.Empty Then If Double.TryParse(txtParking.Text, dblSaved) Then If (dblPARKING * CDbl(txtParking.Text)) - CalcParkingFees() > 0 Then dblSaved += (dblPARKING * CDbl(txtParking.Text)) - CalcParkingFees() End If End If End If If Not txtTaxi.Text = String.Empty Then If Double.TryParse(txtTaxi.Text, dblSaved) Then If (dblTAXI * CDbl(txtTaxi.Text)) - CalcTaxiFees() > 0 Then dblSaved += (dblTAXI * CDbl(txtTaxi.Text)) - CalcTaxiFees() End If End If End If If Not txtLodge.Text = String.Empty Then If Double.TryParse(txtLodge.Text, dblSaved) Then If (dblLODGE * CDbl(txtLodge.Text)) - CalcLodging() > 0 Then dblSaved += (dblLODGE * CDbl(txtDaysTrip.Text)) - CalcLodging() End If End If End If Return (dblSaved) End Function End Class
Travel ExpensesApplication must calculate and display total travel expenses the probl
Page 1 of 1
6 Replies - 5097 Views - Last Post: 03 December 2009 - 07:27 PM
#1
Travel Expenses
Posted 09 May 2009 - 04:55 AM
Replies To: Travel Expenses
#2
Re: Travel Expenses
Posted 09 May 2009 - 06:50 AM
Please type the question in the body, not the title.
Tell us of any problems that may occur when starting the program.
Give details to what your program does.
Thanks.
AND this is a VB.NET question.
Tell us of any problems that may occur when starting the program.
Give details to what your program does.
Thanks.
AND this is a VB.NET question.
#3
Re: Travel Expenses
Posted 09 May 2009 - 07:19 AM
Changed title for clarity.
Moving to VB.NET
Moving to VB.NET
#4
Re: Travel Expenses
Posted 09 May 2009 - 11:18 AM
So, what is the problem??? Tell us what is does and what it doesn't do, or what you don't know how to do.
Remember that we don't see you forms in the post and it would require some effort on our side to fake up a working copy.
Also, tell use what the program specification is - what's it supposed to do as in what your assignment said you were to make it do.
Remember that we don't see you forms in the post and it would require some effort on our side to fake up a working copy.
Also, tell use what the program specification is - what's it supposed to do as in what your assignment said you were to make it do.
#5
Re: Travel Expenses
Posted 09 May 2009 - 06:14 PM
Hi yes my problem is that the code is not calculating right I need to create an application that calculates and displays the total travel expenses for a business trip.
It's going to include number of days, miles driven, Parking fees, Taxi Charges, Lodging charges. The company reimburses travel expenses $37 per day for meals Parking fees up to $10 per day Taxi Charges up to $20 per day Lodging charges up to $95.00 per day and miles driven 0.27 per mile.
It's going to calculate Total Expenses incurred by the business person. The total allowable expenses for the trip. The excess that must be paid by the business person, if any. The amount saved by the business person if the expenses were under the total allowed.
I went through and have dimmed out what I don't need at all however I am still having problems in my calculations.
It's going to include number of days, miles driven, Parking fees, Taxi Charges, Lodging charges. The company reimburses travel expenses $37 per day for meals Parking fees up to $10 per day Taxi Charges up to $20 per day Lodging charges up to $95.00 per day and miles driven 0.27 per mile.
It's going to calculate Total Expenses incurred by the business person. The total allowable expenses for the trip. The excess that must be paid by the business person, if any. The amount saved by the business person if the expenses were under the total allowed.
I went through and have dimmed out what I don't need at all however I am still having problems in my calculations.
Option Strict On Option Explicit On Public Class Form1 'James Blakeman 'May 7, 2009 'Application takes all calculations of user's inputed data. 'Constants Const dblMEALS As Double = 37 Const dblMIlES As Double = 0.27 Const dblPARKING As Double = 10 Const dblTAXI As Double = 20 Const dblLODGE As Double = 95 Private Sub btnCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalc.Click 'Dim statements Dim dblTotal As Double Dim dblSaved As Double Dim dblReimbursed As Double Dim dblUnallowed As Double dblTotal = CalcMeals() + CalcLodging() + CalcParkingFees() + CalcTaxiFees() + CalcMileage() lblCustomerTotal.Text = FormatCurrency(dblTotal.ToString) dblReimbursed = CalcTotalReimbursement() lblAllowed.Text = FormatCurrency(dblReimbursed.ToString) dblSaved = CalcSaved() lblSaved.Text = FormatCurrency(dblSaved.ToString) dblUnallowed = CalcUnallowed() lblOverage.Text = FormatCurrency(dblUnallowed.ToString) End Sub Function CalcMeals() As Double 'Dim Statement Dim dblTotalMeal As Double If Not txtDaysTrip.Text = String.Empty Then If Double.TryParse(txtDaysTrip.Text, dblTotalMeal) Then dblTotalMeal = dblMEALS * CDbl(txtDaysTrip.Text) End If End If Return (dblTotalMeal) End Function Function CalcMileage() As Double 'Dim Statement Dim dblTotalMiles As Double If Not txtMiles.Text = String.Empty Then If Double.TryParse(txtMiles.Text, dblTotalMiles) Then dblTotalMiles = dblMIlES * CDbl(txtMiles.Text) End If End If Return (dblTotalMiles) End Function Function CalcParkingFees() As Double 'Dim Statement Dim dblParkingTotal As Double If Not txtParking.Text = String.Empty Then If Double.TryParse(txtParking.Text, dblParkingTotal) Then dblParkingTotal = dblPARKING * CDbl(txtDaysTrip.Text) End If End If Return (dblParkingTotal) End Function Function CalcTaxiFees() As Double 'Dim Statement Dim dblTaxiTotal As Double If Not txtTaxi.Text = String.Empty Then If Double.TryParse(txtTaxi.Text, dblTaxiTotal) Then dblTaxiTotal = dblTAXI * CDbl(txtDaysTrip.Text) End If End If Return (dblTaxiTotal) End Function Function CalcLodging() As Double 'Dim Statement Dim dblLodgeTotal As Double If Not txtLodge.Text = String.Empty Then If Double.TryParse(txtLodge.Text, dblLodgeTotal) Then dblLodgeTotal = dblLODGE * CDbl(txtDaysTrip.Text) End If End If Return (dblLodgeTotal) End Function Function CalcTotalReimbursement() As Double 'Dim Statement Dim dblTotalReimbursed As Double If Not txtDaysTrip.Text = String.Empty Then If Double.TryParse(txtDaysTrip.Text, dblTotalReimbursed) Then 'If (CalcMeals() / CDbl(txtDaysTrip.Text)) < dblMEALS Then dblTotalReimbursed += CalcMeals() ' Else 'dblTotalReimbursed += dblMEALS * CDbl(txtDaysTrip.Text) End If End If 'End If If Not txtMiles.Text = String.Empty Then If Double.TryParse(txtMiles.Text, dblTotalReimbursed) Then If (CalcMileage() / CDbl(txtMiles.Text)) < dblMIlES Then dblTotalReimbursed += CalcMileage() Else dblTotalReimbursed += dblMIlES * CDbl(txtMiles.Text) End If End If End If If Not txtParking.Text = String.Empty Then If Double.TryParse(txtParking.Text, dblTotalReimbursed) Then If (CalcParkingFees() / CDbl(txtParking.Text)) < dblPARKING Then dblTotalReimbursed += CalcParkingFees() Else dblTotalReimbursed += dblPARKING * CDbl(txtParking.Text) End If End If End If If Not txtTaxi.Text = String.Empty Then If Double.TryParse(txtTaxi.Text, dblTotalReimbursed) Then If (CalcTaxiFees() / CDbl(txtTaxi.Text)) < dblTAXI Then dblTotalReimbursed += CalcTaxiFees() Else dblTotalReimbursed += dblTAXI * CDbl(txtTaxi.Text) End If End If End If If Not txtLodge.Text = String.Empty Then If Double.TryParse(txtLodge.Text, dblTotalReimbursed) Then 'If (CalcLodging() / CDbl(txtDaysTrip.Text)) < dblLODGE Then 'dblTotalReimbursed += CalcLodging() ' Else dblTotalReimbursed += dblLODGE * CDbl(txtDaysTrip.Text) End If End If ' End If Return (dblTotalReimbursed) End Function Function CalcUnallowed() As Double 'Dim Statement Dim dblUnallowed As Double 'If Not txtDaysTrip.Text = String.Empty Then 'If Double.TryParse(txtDaysTrip.Text, dblUnallowed) Then ' If (CalcMeals() / CDbl(txtDaysTrip.Text)) > dblMEALS Then 'dblUnallowed += CalcMeals() - (dblMEALS * CDbl(txtDaysTrip.Text)) 'End If ' End If ' End If 'If Not txtMiles.Text = String.Empty Then 'If Double.TryParse(txtMiles.Text, dblUnallowed) Then 'If (CalcMileage() / CDbl(txtMiles.Text)) > dblMIlES Then 'dblUnallowed += CalcMileage() - (dblMIlES * CDbl(txtMiles.Text)) 'End If 'End If ' End If If Not txtParking.Text = String.Empty Then If Double.TryParse(txtParking.Text, dblUnallowed) Then If (CalcParkingFees() - CDbl(txtParking.Text)) > 0 Then dblUnallowed += CalcParkingFees() - (dblPARKING * CDbl(txtParking.Text)) End If End If End If If Not txtTaxi.Text = String.Empty Then If Double.TryParse(txtTaxi.Text, dblUnallowed) Then If (CalcTaxiFees() - CDbl(txtTaxi.Text)) > 0 Then dblUnallowed += CalcTaxiFees() - (dblTAXI * CDbl(txtTaxi.Text)) End If End If End If If Not txtLodge.Text = String.Empty Then If Double.TryParse(txtLodge.Text, dblUnallowed) Then If (CalcLodging() - CDbl(txtLodge.Text)) > 0 Then dblUnallowed += CalcLodging() - (dblLODGE * CDbl(txtDaysTrip.Text)) End If End If End If Return dblUnallowed End Function Function CalcSaved() As Double 'Dim Statement Dim dblSaved As Double 'If Not txtDaysTrip.Text = String.Empty Then 'If Double.TryParse(txtDaysTrip.Text, dblSaved) Then ' If (dblMEALS * CDbl(txtDaysTrip.Text)) - CalcMeals() > 0 Then 'dblSaved += (dblMEALS * CDbl(txtDaysTrip.Text)) - CalcMeals() 'End If ' End If 'End If 'If Not txtMiles.Text = String.Empty Then 'If Double.TryParse(txtMiles.Text, dblSaved) Then 'If (dblMIlES * CDbl(txtMiles.Text)) - CalcMileage() > 0 Then 'dblSaved += (dblMIlES * CDbl(txtMiles.Text)) - CalcMileage() 'End If 'End If 'End If If Not txtParking.Text = String.Empty Then If Double.TryParse(txtParking.Text, dblSaved) Then If (dblPARKING * CDbl(txtParking.Text)) - CalcParkingFees() > 0 Then dblSaved += (dblPARKING * CDbl(txtParking.Text)) - CalcParkingFees() End If End If End If If Not txtTaxi.Text = String.Empty Then If Double.TryParse(txtTaxi.Text, dblSaved) Then If (dblTAXI * CDbl(txtTaxi.Text)) - CalcTaxiFees() > 0 Then dblSaved += (dblTAXI * CDbl(txtTaxi.Text)) - CalcTaxiFees() End If End If End If If Not txtLodge.Text = String.Empty Then If Double.TryParse(txtLodge.Text, dblSaved) Then If (dblLODGE * CDbl(txtLodge.Text)) - CalcLodging() > 0 Then dblSaved += (dblLODGE * CDbl(txtDaysTrip.Text)) - CalcLodging() End If End If End If Return (dblSaved) End Function
#6
Re: Travel Expenses
Posted 03 December 2009 - 12:03 PM
Hi. I am Jimika. I just wanted to know did you get the code corrected. I'm doing my project now for class and I am also having trouble with the calculations. Mainly because we have to do the reimbursements (allowable) and the unallowable. I'm just having a hard time understanding how to write the code its self. Did looking at some of the examples in the book help you as well?
#7
Re: Travel Expenses
Posted 03 December 2009 - 07:27 PM
Your logic is not what I would expect for this project. Your inputs should be totalDays, totalMiles, totalMeals, totalParking, totalTaxis and totalLodging. These are the totals that they spent and are an input, not a calculation. The calculations are:
1) totalSpent = totalMeals + totalParking + totalTaxis + totalLodging
2) for each of the components you need a covered value - e.g. coveredMeals = totalDays * mealAllowance
3) then for each of the components you need to determine the amount refundable. e.g.
A negative uncoveredTotal is "saved" expenses, a positive is uncovered expenses. This assumes that any savings in say meals can offset over-runs in lodging. If this is not the case, then move the uncovered calculation into the Else portion and add a savedTotal calculation into the Then portion.
4) Don't forget to add the mileage calc to refundTotal (a global variable).
1) totalSpent = totalMeals + totalParking + totalTaxis + totalLodging
2) for each of the components you need a covered value - e.g. coveredMeals = totalDays * mealAllowance
3) then for each of the components you need to determine the amount refundable. e.g.
If coveredMeals > totalMeals Then refundTotal = totalMeals Else refundTotal = coveredMeals End If uncoveredTotal = totalMeals - coveredMeals
A negative uncoveredTotal is "saved" expenses, a positive is uncovered expenses. This assumes that any savings in say meals can offset over-runs in lodging. If this is not the case, then move the uncovered calculation into the Else portion and add a savedTotal calculation into the Then portion.
4) Don't forget to add the mileage calc to refundTotal (a global variable).
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|