This is my second attempt and for some reason won't Calculate. I get $0.00 as my result. VB tells me something is wrong wth CalcMiscCharge missing a return statement, but don't see where. Any Ideas?
Public Class Form1
Private decLabFee As Decimal ' To hold Lab fee.
Private decMeds As Decimal 'To hold Medication cost.
Private decSurgical As Decimal 'To hold Surgical cost.
Private intLengthOfStay As Integer 'Amount of days stayed at hospital.
Private decPhycical As Decimal 'Hold Amount of Physical Cost.
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
Dim StayCharge As Decimal
Dim MiscCharge As Decimal
Dim TotalCost As Decimal
StayCharge = CalcStayCharge(txtLengthOfStay.Text)
MiscCharge = CalcMiscCharges(txtMeds.Text, txtSurgical.Text, txtLabFee.Text, txtPhysical.Text)
TotalCost = CalcTotalCharges(StayCharge, MiscCharge)
lblTotalCost.Text = FormatCurrency(TotalCost)
End Sub
Function CalcStayCharge(ByVal txtLengthOfStay As String) As Decimal
'Calcuate Stay Charges.
Dim StayCharge As Decimal
Dim NumDays As Decimal
Try
NumDays = txtLengthOfStay
Catch ex As Exception
MessageBox.Show("All Charges Must Be Zero or More", "CHECK INPUT!")
End Try
If NumDays < 0 Then
MessageBox.Show("Length of Stay Can Not be less than Zero", "Negative Number ERROR!")
Return 0
End If
StayCharge = NumDays * 350
Return StayCharge
End Function
Function CalcMiscCharges(ByVal Meds As Decimal, ByVal LabFee As Decimal,
ByVal Physical As Decimal, ByVal Surgical As Decimal) As Decimal
Dim MiscCharges As Decimal
Try
Meds = CDec(txtMeds.Text)
Surgical = CDec(txtSurgical.Text)
Physical = CDec(txtPhysical.Text)
LabFee = CDec(txtLabFee.Text)
Catch ex As Exception
MessageBox.Show("All Charges Must Be Zero or More", "Negative Number ERROR!")
GoTo ReDo
End Try
If Meds < 0 Or Surgical < 0 Or LabFee < 0 Or Physical < 0 Then
MessageBox.Show("You May not enter a Minus Charge", "Negative Chare ERROR!")
GoTo ReDo
End If
MiscCharges = Meds + Surgical + LabFee + Physical
Return MiscCharges
ReDo:
End Function
Function CalcTotalCharges(ByVal StayCharge As Decimal, ByVal MiscCharge As Decimal) As Decimal
Dim TotalCost As Decimal
Dim StayCharges As Decimal
Dim MiscCharges As Decimal
TotalCost = StayCharges + MiscCharges
CalcTotalCharges = CDec(TotalCost.ToString)
Return CalcTotalCharges + MiscCharges
End Function
Private Sub btnClear_Click(sender As Object, e As EventArgs) Handles btnClear.Click
'Clears all text boxes
txtLengthOfStay.Clear()
txtMeds.Clear()
txtSurgical.Clear()
txtLabFee.Clear()
txtPhysical.Clear()
'Clear label boxes
lblTotalCost.Text = String.Empty
End Sub
End Class