I created the form (5 text boxes which contain a) Length of stay then b-e) are misc charges, the purpose is to add items a through e and display in a label). I have been asked to use three functions and was given the names CalcStayCharges, CalcMiscCharges and CalcTotalCharges.
I can get the form working somewhat in that it calculates but I am not calling function CalcTotalCharges as you can see in the code. If I only call CalcTotalCharges, the form doesnt work. I stepped through and it seems there is no value in CalcTotalCharges but I cannot work out why.
My questions are: 1) Why is my third function empty and 2) how would I call all three functions. Would it be proper to just call the third function? I did try calling the functions into CalcTotalCharges by name but all three functions ended up with no value!
I can get the form working somewhat in that it calculates but I am not calling function CalcTotalCharges as you can see in the code. If I only call CalcTotalCharges, the form doesnt work. I stepped through and it seems there is no value in CalcTotalCharges but I cannot work out why.
My questions are: 1) Why is my third function empty and 2) how would I call all three functions. Would it be proper to just call the third function? I did try calling the functions into CalcTotalCharges by name but all three functions ended up with no value!
Code:
ublic Class Form1
Function CalcStayCharges(ByVal dblLengthOfStay As Double) As Double
'Declare Variables.
Dim dblCostPerNight As Double = 350D 'Holds the charge per night.
Dim dblStayCharges As Double 'Holds the cost per day x number of days stayed.
'To calculate Cost of stay.
dblStayCharges = dblLengthOfStay * dblCostPerNight
Return dblStayCharges
End Function
Function CalcMiscCharges(ByVal dblMedication As Double, ByVal dblSurgical As Double,
ByVal dblLabFees As Double, ByVal dblphysical As Double) As Double
'Declare Variable
Dim dblMiscCharges As Double 'Holds the cost of all miscellaneous charges.
'To calculate the total of all miscellaneous charges.
dblMiscCharges = dblMedication + dblSurgical + dblLabFees + dblphysical
Return dblMiscCharges
End Function
Function CalcTotalCharges(ByVal dblTotalCost As Double) As Double
'Declare Variables.
Dim dblStayCharges As Double 'Holds the cost per day x number of days stayed.
Dim dblMiscCharges As Double 'Holds the total cost of all miscellaneous charges.
Dim dblTotalCharges As Double 'Holds the cost of stay plus the cost of miscellaneous charges.
'To calculate the cost of all charges.
dblTotalCharges = dblStayCharges + dblMiscCharges
Return dblTotalCharges
End Function
Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
'Declare variables.
Dim dblLengthOfStay As Double 'Holds number of days.
Dim dblMedication As Double 'Holds cost of medication.
Dim dblSurgical As Double 'Holds cost surgical charges.
Dim dblLabFees As Double 'Holds cost of Lab Fees.
Dim dblPhysical As Double 'holds cost of Physical.
Dim dblTotalCost As Double 'Holds the total of the costofstay and the miscCosts.
'Validate user input is numeric and more than or equal to 0.
If Not Double.TryParse(txtLengthOfStay.Text, dblLengthOfStay) OrElse
Not Double.TryParse(txtMedication.Text, dblMedication) OrElse
Not Double.TryParse(txtSurgical.Text, dblSurgical) OrElse
Not Double.TryParse(txtLabFees.Text, dblLabFees) OrElse
Not Double.TryParse(txtPhysical.Text, dblPhysical) Then
'Display error message.
MessageBox.Show("all values must be numeric and Zero or more", "Invalid Input")
Else
'Get Total cost of Hospital Stay
dblTotalCost = CalcStayCharges(dblLengthOfStay) +
CalcMiscCharges(dblMedication, dblSurgical, dblLabFees, dblPhysical)
'Display Total cost of Hospital stay in Label
lblTotalCost.Text = FormatCurrency(dblTotalCost, 2)
End If
End Sub