Results 1 to 6 of 6

Thread: Hospital Charges form

Threaded View

  1. #1

    Thread Starter
    New Member
    Join Date
    Nov 2009
    Posts
    9

    Hospital Charges form

    Trying to figure out why exactly it will display the total value of decMiscCharges + decCharges. Any advice would be appreciated.
    vb.net Code:
    1. Option Strict On
    2. Option Explicit On
    3. Public Class Form1
    4.  
    5.     Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculateCharges.Click
    6.  
    7.         'declare all variables
    8.         Dim decCharge As Decimal
    9.         Dim intLengthOfStay As Integer
    10.         Dim decMedCharges As Decimal
    11.         Dim decSurgicalCharge As Decimal
    12.         Dim decDayRate As Decimal
    13.         Dim decMiscCharge As Decimal
    14.         Dim decSurgicalCharges As Decimal
    15.         Dim decTotalCharge As Decimal
    16.         Dim decMeds As Decimal
    17.         Dim decLabFee As Decimal
    18.  
    19.         If isValid(decMeds, decSurgicalCharge, intLengthOfStay, decLabFee) = True Then
    20.             decCharge = CalcStayCharge(intLengthOfStay, decDayRate)
    21.             decMiscCharge = CalcMiscCharges(decMedCharges, decSurgicalCharges, decLabFee)
    22.             decTotalCharge = CalcTotalCharge(decMiscCharge, decCharge)
    23.             txtTotalCost.Text = decTotalCharge.ToString("c2")
    24.         End If
    25.  
    26.     End Sub
    27.  
    28.     Private Function isValid(ByRef decMeds As Decimal, ByRef decSurgeicalCharge As Decimal, _
    29.                             ByRef intLengthOfStay As Integer, ByRef decLabFee As Decimal) As Boolean
    30.  
    31.         Return isValidStay(intLengthOfStay) AndAlso isValidMedication(decMeds) _
    32.         AndAlso isValidSurgical(decSurgeicalCharge) AndAlso CBool(isValidLabFee(decLabFee))
    33.  
    34.         Return isValid
    35.     End Function
    36.  
    37.     Private Function isValidStay(ByRef intLengthOfStay As Integer) As Boolean
    38.         'Declare Boolean
    39.         Dim isGood As Boolean
    40.         'Declare Constants
    41.         Const c_DaysError As String = "Length of stay must be a whole number between 0 and 100"
    42.         Try
    43.             intLengthOfStay = Convert.ToInt32(txtLengthOfDays.Text)
    44.             If intLengthOfStay >= 0 And intLengthOfStay <= 100 Then
    45.                 isGood = True
    46.             Else
    47.                 isGood = False
    48.             End If
    49.         Catch ex As Exception
    50.             isGood = False
    51.         End Try
    52.         If isGood = False Then
    53.             MessageBox.Show(c_DaysError)
    54.             txtLengthOfDays.SelectAll()
    55.             txtLengthOfDays.Focus()
    56.         End If
    57.         Return isGood
    58.     End Function
    59.  
    60.     Public Function isValidLabFee(ByVal decLabFee As Decimal) As Decimal
    61.  
    62.         'Declare Variable
    63.         Dim isGood As Boolean
    64.         'Declare Constant
    65.         Const c_LabFeeError As String = "Medication must be between 0 and 10,000"
    66.  
    67.         Try
    68.             decLabFee = Convert.ToDecimal(txtLabFees.Text)
    69.             If decLabFee >= 0D And decLabFee <= 10000D Then
    70.                 isGood = True
    71.             Else
    72.                 isGood = False
    73.             End If
    74.         Catch ex As Exception
    75.             isGood = False
    76.             MessageBox.Show(c_LabFeeError)
    77.             txtLabFees.SelectAll()
    78.             txtLabFees.Focus()
    79.         End Try
    80.         Return CDec(isGood)
    81.     End Function
    82.  
    83.     Public Function isValidMedication(ByVal decMedCharges As Decimal) As Boolean
    84.  
    85.         'Declare Variable
    86.         Dim isGood As Boolean
    87.         'Declare Constant
    88.         Const c_MedicationError As String = "Medication must be between 0 and 10,000"
    89.  
    90.         Try
    91.             decMedCharges = Convert.ToDecimal(txtMedicationCharges.Text)
    92.             If decMedCharges >= 0D And decMedCharges <= 10000D Then
    93.                 isGood = True
    94.             Else
    95.                 isGood = False
    96.             End If
    97.         Catch ex As Exception
    98.             isGood = False
    99.             MessageBox.Show(c_MedicationError)
    100.             txtMedicationCharges.SelectAll()
    101.             txtMedicationCharges.Focus()
    102.         End Try
    103.         Return isGood
    104.     End Function
    105.  
    106.     Public Function isValidSurgical(ByVal decSurgicalCharges As Decimal) _
    107.     As Boolean
    108.  
    109.         'Declare Variables
    110.         Dim isGood As Boolean
    111.         'Declare constants
    112.         Const c_SurgicalError As String = "Surgical must be between 0 and 500,000"
    113.  
    114.         Try
    115.             decSurgicalCharges = Convert.ToDecimal(txtSurgicalCharges.Text)
    116.             If decSurgicalCharges >= 0D And decSurgicalCharges <= 500000D Then
    117.                 isGood = True
    118.             Else
    119.                 isGood = False
    120.             End If
    121.         Catch ex As Exception
    122.             isGood = False
    123.             MessageBox.Show(c_SurgicalError)
    124.             txtSurgicalCharges.SelectAll()
    125.             txtSurgicalCharges.Focus()
    126.         End Try
    127.         Return isGood
    128.     End Function
    129.  
    130.     Private Sub txtLabFees_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtLabFees.TextChanged
    131.  
    132.     End Sub
    133. End Class
    134.  
    135. Module modTotalCharge
    136.     Public Function CalcTotalCharge(ByRef decMiscCharge As Decimal, ByRef decCharge As Decimal) _
    137.     As Decimal
    138.         Return decMiscCharge + decCharge
    139.     End Function
    140. End Module
    141.  
    142. Module modMiscCharge
    143.     Function CalcMiscCharges(ByRef decMedCharges As Decimal, ByRef decSurgicalCharges As Decimal, ByRef decLabFee As Decimal) _
    144.     As Decimal
    145.         Return decMedCharges + decSurgicalCharges + decLabFee
    146.     End Function
    147. End Module
    148.  
    149. Module modStayCharge
    150.     Public Function CalcStayCharge(ByVal intLengthofStay As Integer, ByVal decDayRate As Decimal) _
    151.     As Decimal
    152.         decDayRate = 350D
    153.         Return intLengthofStay * decDayRate
    154.     End Function
    155. End Module
    Last edited by Hack; Dec 4th, 2009 at 06:51 AM. Reason: Added Highlight Tags

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width