|
|
#1 |
|
Addicted Member
Join Date: Feb 07
Location: The Great State of Texas
Posts: 160
![]() |
I need someone to explain to me why this code constantly returns a 0 value when I attmept to run this program. I'm about at my witts end and ready to jump out of a window of a very tall building!
HTML Code:
Public Class FrmTravel
'Define all variables to be used within the application
'both locally and form wide.
Dim decDays As Decimal
Dim decAirfare As Decimal
Dim decCarRentals As Decimal
Dim sngMiles As Single
Dim decParkingFees As Decimal
Dim decTaxi As Decimal
Dim decSeminar As Decimal
Dim decLodging As Decimal
Dim decTotalCost As Decimal
Dim decAmountExempt As Decimal
Dim decEndCost As Decimal
Dim decMeals As Decimal 'price put in by user
Dim decMealIncurred As Decimal 'price going in incurred txtbox
Dim decMealTotal As Decimal
Dim decMealExempt As Decimal 'going into the exempt txtbox
'All constants listed. Each value is the maximum
'amount that is reimbursable by the company.
Const conMEALS As Decimal = 37D
Const conPARKINGFEES As Decimal = 10D
Const conTAXI As Decimal = 20D
Const conLODGING As Decimal = 95D
Const conPRIVATE As Decimal = 0.27D
'Submit the calcMeals sub to determine the cost of food
'and what is reimbursable.
Function calcMeals() As Decimal
decDays = CDec(cboDays.SelectedItem().ToString)
decMeals = CDec(txtMeals.Text.ToString)
decMealTotal = decMeals / decDays
Return decMealTotal
End Function
Private Sub btnCalcCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcCost.Click
'process to begin reimbursement of money if any is due.
If calcMeals() > conMEALS Then
lblTotalCost.Text = FormatCurrency(CDec(calcMeals()))
End If
Thanks, Abe
__________________
Abrium Asking the beginners questions so you don't have to! ![]() If by chance hell actually froze over and I some how helped you... Please rate. |
|
|
|
|
|
#2 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: [2005] Help with calling functions
Have you tried doing some messageboxes or debug statements to see what is being returned. A good place to start would be to see whether the values returned by cboDays and txtMeals are what you expect them to be.
Hope this helps
__________________
If your problem has been solved then please mark the thread [RESOLVED]. If i have helped then please Rate my post |
|
|
|
|
|
#3 |
|
Addicted Member
Join Date: Feb 07
Location: The Great State of Texas
Posts: 160
![]() |
Re: [2005] Help with calling functions
Yeah I have been using a lbl on the form to test the inputs to the mathematics that I'm performing. Those come out completely correct. I know the problem is involved with the click event on the calc button... at least I am pretty sure, been looking at this problem for about 12 hours now and I think I'm doing more harm then good.
__________________
Abrium Asking the beginners questions so you don't have to! ![]() If by chance hell actually froze over and I some how helped you... Please rate. |
|
|
|
|
|
#4 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: [2005] Help with calling functions
Well put a messagebox before the return line in the function and see what value decMealTotal is and then in another messagebox in the button click function say
messagebox.show(calcMeals().tostring) What do they say?
__________________
If your problem has been solved then please mark the thread [RESOLVED]. If i have helped then please Rate my post |
|
|
|
|
|
#5 |
|
Fanatic Member
Join Date: Aug 06
Posts: 734
![]() |
Re: [2005] Help with calling functions
Also just as an observation....i dont think you need to do CDec(calcMeals()) in the button click event because you are already returning a decimal.
__________________
If your problem has been solved then please mark the thread [RESOLVED]. If i have helped then please Rate my post |
|
|
|
|
|
#6 |
|
Addicted Member
Join Date: Feb 07
Location: The Great State of Texas
Posts: 160
![]() |
Now I have it working but it seems that its making me put a lot of redunant code as you can see with the section I posted below. I have class wide variables declared but yet it makes me declare them per subroutine. Good news is the math started working, although I really hate to swap one problem for another one.
Code:
Dim decMeals As Decimal 'price put in by user
Dim decMealExempt As Decimal 'going into the exempt txtbox
Dim decTotalfood As Decimal 'total cost of food on trip
'All constants listed. Each value is the maximum
'amount that is reimbursable by the company.
Const conMEALS As Decimal = 37D
Const conPARKINGFEES As Decimal = 10D
Const conTAXI As Decimal = 20D
Const conLODGING As Decimal = 95D
Const conPRIVATE As Decimal = 0.27D
'Submit the calcMeals sub to determine the cost of food
'and what is reimbursable.
Function calcMeals(ByVal decMealTotal As Decimal) As Decimal
decDays = CDec(cboDays.SelectedItem().ToString)
decMeals = CDec(txtMeals.Text.ToString)
decMealTotal = decMeals / decDays
Return decMealTotal
End Function
Private Sub btnCalcCost_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalcCost.Click
'process to begin reimbursement of money if any is due.
Dim decMealTotal As Decimal
Dim decMealExempt As Decimal
'MessageBox.Show(CDec(calcMeals(decMealTotal)).ToString)
If (calcMeals(decMealTotal)) > conMEALS Then
decMealExempt = 0
lblTotalCost.Text = (CStr((calcMeals(decMealTotal))))
End If
__________________
Abrium Asking the beginners questions so you don't have to! ![]() If by chance hell actually froze over and I some how helped you... Please rate. |
|
|
|
![]() |
|
||||||
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | Search this Thread |
| Display Modes | |
|
|