所以我写这个程序应该可以返回住院的总费用。一切似乎都很好,除了最重要的部分......住院的总费用。我到处寻找可能的解决方案,但无济于事。无论我做什么,程序都会继续返回0.00美元。没有错误消息,每次只需0.00美元。我意识到我还没有包含异常处理,一旦我解决了问题,我会做的。知道我的问题在这里吗?提前谢谢!
Const decRatePerDay As Decimal = 350.0
Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim NumOfDays As Integer
Dim MedCharges As Decimal
Dim SurgicalCharges As Decimal
Dim LabFees As Decimal
Dim RehabCharges As Decimal
Dim TotalCharges As Decimal
NumOfDays = CDec(txtNumOfDays.Text)
MedCharges = CDec(txtMedCharges.Text)
SurgicalCharges = CDec(txtSurgicalCharges.Text)
LabFees = CDec(txtLabFees.Text)
RehabCharges = CDec(txtLabFees.Text)
lblCalTotalCost.Text = TotalCharges.ToString("c")
End Sub
Function CalcStayCharges(NumOfDays As Integer) As Decimal
Dim decCostOfStay As Decimal
NumOfDays = CDec(txtNumOfDays.ToString)
decCostOfStay = NumOfDays * decRatePerDay
Return decCostOfStay
End Function
Function CalcMiscCharges(MedCharges As Decimal, SurgicalCharges As Decimal, LabFees As Decimal, RehabCharges As Decimal) As Decimal
Dim TotalMisc As Decimal
MedCharges = CDec(txtMedCharges.ToString)
SurgicalCharges = CDec(txtSurgicalCharges.ToString)
LabFees = CDec(txtLabFees.ToString)
RehabCharges = CDec(txtLabFees.ToString)
TotalMisc = MedCharges + SurgicalCharges + LabFees + RehabCharges
Return TotalMisc
End Function
Function CalcTotalCharges(CostOfStay As Decimal, TotalMisc As Decimal) As Decimal
Dim TotalCharges As Decimal
TotalCharges = CostOfStay + TotalMisc
lblCalTotalCost.Text = TotalCharges.ToString("c")
Return TotalCharges
End Function
答案 0 :(得分:2)
您永远不会设置TotalCharges
的值,也不会调用您的函数来计算总费用。
更改
lblCalTotalCost.Text = TotalCharges.ToString("c")
要
lblCalTotalCost.Text = CalcTotalCharges(CalcStayCharges(NumOfDays), _
CalcMiscCharges(MedCharges, SurgicalCharges, LabFees, RehabCharges)) _
.ToString("C")