I am attempting to get the average cost of fuel purchased per trip.
My code snippets are as follows:
Private Sub calc()
Dim
a, f1, f2, f3, f4, f5, f6 As Decimal
Try
f1 = CDec(IIf(tbTruckFuelPurchased.Text.Trim = "", 0D, tbTruckFuelPurchased.Text.Trim))
f2 = CDec(IIf(tbReeferFuelPurchased.Text.Trim = "", 0D, tbReeferFuelPurchased.Text.Trim))
f3 = CDec(IIf(tbDEFPurchased.Text.Trim = "", 0D, tbDEFPurchased.Text.Trim))
f4 = CDec(IIf(tbGalsPurch.Text.Trim = "", 0D, tbGalsPurch.Text.Trim))
f5 = CDec(IIf(tbREF_Gals.Text.Trim = "", 0D, tbREF_Gals.Text.Trim))
f6 = CDec(IIf(tbFuelCostAvg.Text.Trim = "", 0D, tbFuelCostAvg.Text.Trim))
Catch ex As Exception
'If a calculation error occurs, show Error message box
Dim frm As New MeMsgCalcError(ex, "Error in 'Calculation DIM Statement' Defining Area.")
frm.Show()
End Try
'Calculate Average Cost of Fuel this Load
Try
a = f1 \ f4
tbFuelCostAvg.Text = a.ToString("C2")
Catch ex As Exception
'If a calculation error occurs, show Error message box
Dim frm As New MeMsgCalcError(ex, "Calculation Error in 'Average Cost of Fuel this Load.'")
frm.Show()
End Try
This errors out noting:
Error BC30512
Option Strict On disallows implicit conversions from 'Decimal' to 'Long'.
As noted above in the error message, Option Strict is On and needs to be so.
How might I take the total fuel purchased (tbTruckFuelPurchased (currency)) and divide total fuel gallons purchased (tbGalsPurch (whole number plus 3 decimals) to end up with an average cost per gallon? Obviously I am looking for a "money" returned value rounded to 2 decimals.
I am not understanding the conversion from Decimal to Long error message.
What I have tried:
See message for code and tries.