Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please Help! Im doing the Visual basic 7th edition programming challenge hospita

ID: 3582915 • Letter: P

Question

Please Help! Im doing the Visual basic 7th edition programming challenge hospital charges. For some reason it wont calculate my total cost I think there is a problem with one line of code. This is my code, Its telling me there is a problem with the txtTotalCost.Text but i cant figure out what the problem is. Thank you.

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim decdays As Decimal 'To hold number of days.
Dim decmedication As Decimal 'To hold medication charges.
Dim decsurgical As Decimal 'To hold surgical charges.
Dim declabfee As Decimal 'To hold lab fees.
Dim decphysical As Decimal 'To hold physical.
Dim dectotalcost As Decimal 'To hold Total cost.
txtLengthofStay.Focus()
decdays = CDec(txtLengthofStay.Text)
decmedication = CDec(txtMedication.Text)
decsurgical = CDec(txtSurgical.Text)
declabfee = CDec(txtLabFees.Text)
declabfee = CDec(txtLabFees.Text)
decphysical = CDec(txtPhysical.Text)
Dim charges As Decimal
Dim totalMisccharges As Decimal
txtLengthofStay.Focus()
If decdays >= 0 And decmedication >= 0 And decsurgical >= 0 And declabfee >= 0 And decphysical >= 0 Then
charges = CalcStayCharges(decdays)
totalMisccharges = CalcMisCharges(decmedication, decsurgical, declabfee, decphysical)
dectotalcost = CalcTotalCharges(charges, totalMisccharges) = txtTotalCost.Text
dectotalcost.ToString("n2")
Else
MessageBox.Show("The Values should be numeric")

End If

Explanation / Answer

Here is the modified program as per your requirements.

I have added comments where I modified the code.

Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim decdays As Decimal 'To hold number of days.
Dim decmedication As Decimal 'To hold medication charges.
Dim decsurgical As Decimal 'To hold surgical charges.
Dim declabfee As Decimal 'To hold lab fees.
Dim decphysical As Decimal 'To hold physical.
Dim dectotalcost As Decimal 'To hold Total cost.
txtLengthofStay.Focus()
decdays = CDec(txtLengthofStay.Text)
decmedication = CDec(txtMedication.Text)
decsurgical = CDec(txtSurgical.Text)
declabfee = CDec(txtLabFees.Text)
declabfee = CDec(txtLabFees.Text)
decphysical = CDec(txtPhysical.Text)
Dim charges As Decimal
Dim totalMisccharges As Decimal
txtLengthofStay.Focus()
If decdays >= 0 And decmedication >= 0 And decsurgical >= 0 And declabfee >= 0 And decphysical >= 0 Then
charges = CalcStayCharges(decdays)
totalMisccharges = CalcMisCharges(decmedication, decsurgical, declabfee, decphysical)
dectotalcost = CalcTotalCharges(charges, totalMisccharges) 'Change the code at this line.
txtTotalCost.Text = dectotalcost.ToString("n2") ' Modify the code at this line.
Else
MessageBox.Show("The Values should be numeric")
End If

End Sub