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(sender As Object, e As EventArgs) Handles btnCalculate.Click

        'This Procedure calculate the total amount of a hospital stay

        Dim txtLengthOfStay As Integer
        Dim decLabFee As Decimal
        Dim decMeds As Decimal
        Dim decSurgical As Decimal
        Dim decPhysical As Decimal
        Dim decTotalCharge As Decimal


        'This procedure calculates the total misc expenses of a hospital stay



        If Not Decimal.TryParse(txtSurgical.Text, decSurgical) Then
            MessageBox.Show("Please enter numeric value for surgical charges")

        ElseIf Not Decimal.TryParse(txtLabFee.Text, decLabFee) Then
            MessageBox.Show("Please enter numeric value for Lab Fees")

        ElseIf Not Decimal.TryParse(txtMeds.Text, decMeds) Then
            MessageBox.Show("Please enter numeric value for Medication Charge")

        ElseIf Not Decimal.TryParse(txtPhysical.Text, decPhycical) Then
            MessageBox.Show("Please enter numeric value for Physical Charge")

        ElseIf Not Integer.TryParse(txtLengthOfStay.ToString, intLengthOfStay) Then
            MessageBox.Show("Please enter numeric value for Lenth of stay")

        Else

            'Calculate total charges

            lblTotalCost.Text = () '<~~Not sure what epression I should use here or if I even need it at all



        End If
    End Sub

    Function CalcStayCharge(ByVal Days As Double) As Double

        'Calcuate Stay Charges.
        Dim StayCharge As Double
        StayCharge = Days * 350
        CalcStayCharge = CDbl(StayCharge.ToString)

        MessageBox.Show(CalcStayCharge.ToString("c"))

        lblTotalCost.Text = CStr(CalcStayCharge.ToString)

        Return CalcStayCharge

    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

        Meds = CDec(txtMeds.Text)
        Surgical = CDec(txtSurgical.Text)
        Physical = CDec(txtPhysical.Text)
        LabFee = CDec(txtLabFee.Text)

        'Calculation for Misc Charge

        MiscCharges = Meds + Surgical + Physical + LabFee

        CalcMiscCharges = CDec(MiscCharges.ToString)

        MessageBox.Show(CalcMiscCharges.ToString)

        Return CalcMiscCharges

    End Function

    Function CalcTotalCharges(ByVal TotalCost As Decimal) 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

Recommended Answers

All 3 Replies

Do not understand why did you call a MessageBox in every function and also about the declaration type as Decimal of the variables.
Function is for the use of some value to return. Calling of Message in a function makes an obstraction to do its actual work. Call MessageBox in your procedure if it does not return your desired result.
I make some modification in your code, you can use it if you like.

Public Class Form1


    Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
        Me.Close()
    End Sub
    Private Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
        'This Procedure calculate the total amount of a hospital stay
        Dim decLengthOfStay As Integer
        Dim decLabFee As Double
        Dim decMeds As Double
        Dim decSurgical As Double
        Dim decPhysical As Double

        'This procedure calculates the total misc expenses of a hospital stay

        If Not Integer.TryParse(txtLengthOfStay.Text, decLengthOfStay) Then
            MessageBox.Show("Please enter numeric value for Lenth of stay")
        ElseIf Not Double.TryParse(txtMeds.Text, decMeds) Then
            MessageBox.Show("Please enter numeric value for Medication Charge")
        ElseIf Not Double.TryParse(txtSurgical.Text, decSurgical) Then
            MessageBox.Show("Please enter numeric value for surgical charges")

        ElseIf Not Double.TryParse(txtPhysical.Text, decPhysical) Then
            MessageBox.Show("Please enter numeric value for Physical Charge")
        ElseIf Not Double.TryParse(txtLabFee.Text, decLabFee) Then
            MessageBox.Show("Please enter numeric value for Lab Fees")
        Else
            'Calculate total charges
            lblTotalCost.Text = CalcTotalCharges(CalcStayCharge(decLengthOfStay), CalcMiscCharges(decMeds, decLabFee, decPhysical, decSurgical))

        End If
    End Sub

    Function CalcStayCharge(ByVal Days As Double) As Double
        'Calcuate Stay Charges.
        Return CDbl(Days * 350)
    End Function

    Function CalcMiscCharges(ByVal Meds As Double, ByVal LabFee As Double,
                             ByVal Physical As Double, ByVal Surgical As Double) As Double

        'Calculation for Misc Charge
        Return CDbl(Meds + LabFee + Physical + Surgical)

    End Function

    Function CalcTotalCharges(ByVal StayCharges As Double, ByVal MiscCharges As Double) As Double
        'Calculation for Total Charge
        Return CDbl(StayCharges + 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

Thanks I see what you mean.

Remember if your question is answered you must mark it answered.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.