VB中医院收费功能问题

时间:2013-11-17 22:57:37

标签: vb.net visual-studio-2010 forms function

我正在VB中制作一个程序,我必须使用三种不同的功能来确定我医院收费表中输入数字的成本。一个计算misc费用(CalcMiscCharges),一个计算住院费用(CalcChargesOfStay),一个计算总费用(CalctotalCharges)。使用此当前代码,我输入的任何数字都以0美元回答。任何人都可以看到我的问题所在吗?

Const DayRate As Decimal = 350
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    'declare variables
    Dim PhysicalRehab As Decimal
    Dim SurgeryCharges As Decimal
    Dim LabCharges As Decimal
    Dim MedCharges As Decimal
    Dim StayCharges As Decimal
    Try
        'Copy the scores into the variables
        StayCharges = CDec(TextBoxLength.Text) * DayRate
        MedCharges = CDec(TextBoxMed.Text)
        SurgeryCharges = CDec(TextBoxSurg.Text)
        LabCharges = CDec(TextBoxLab.Text)
        PhysicalRehab = CDec(TextBoxPhy.Text)
    Catch
        MessageBox.Show("Please enter numeric values", "Error")
        Return
    End Try
    'Find out if box enteries are negative or not
    If Convert.ToDecimal(LabCharges) < 0 Then
        MessageBox.Show("No Negative Numbers", "Try Agian")
        Return
        TextBoxLab.SelectAll()
    ElseIf Convert.ToDecimal(MedCharges) < 0 Then
        MessageBox.Show("No Negative Numbers", "Try Agian")
        Return
        TextBoxMed.SelectAll()
    ElseIf Convert.ToDecimal(SurgeryCharges) < 0 Then
        MessageBox.Show("No Negative Numbers", "Try Agian")
        Return
        TextBoxSurg.SelectAll()
    ElseIf Convert.ToDecimal(PhysicalRehab) < 0 Then
        MessageBox.Show("No Negative Numbers", "Try Agian")
        Return
        TextBoxPhy.SelectAll()
    ElseIf Convert.ToDecimal(StayCharges) < 0 Then
        MessageBox.Show("No Negative Numbers", "Try Agian")
        Return
        TextBoxLength.SelectAll()
    End If
    'Sends results to the label
    LabelTotal.Text = CalctotalCharges.ToString("c")
End Sub
Function CalcMiscCharges() As Decimal
    Return CDec(TextBoxMed.Text) + CDec(TextBoxLab.Text) + CDec(TextBoxPhy.Text) + CDec(TextBoxSurg.Text)
End Function
Function CalcChargesOfStay() As Decimal
    Return CalcChargesOfStay = CDec(TextBoxLength.Text) * DayRate
End Function

Function CalctotalCharges() As Decimal
    Return CDec(CalctotalCharges = CDec(CalcChargesOfStay() + CalcMiscCharges()))
End Function

Private Sub ButtonExit_Click(sender As Object, e As EventArgs) Handles ButtonExit.Click
    Me.Close()
End Sub

Private Sub ButtonClear_Click(sender As Object, e As EventArgs) Handles ButtonClear.Click
    TextBoxLab.Clear()
    TextBoxLength.Clear()
    TextBoxMed.Clear()
    TextBoxPhy.Clear()
    TextBoxSurg.Clear()
End Sub

1 个答案:

答案 0 :(得分:1)

在我看来,你在这些函数中混合了两种不同的语法:

Function CalcChargesOfStay() As Decimal
    Return CalcChargesOfStay = CDec(TextBoxLength.Text) * DayRate
End Function

Function CalctotalCharges() As Decimal
    Return CDec(CalctotalCharges = CDec(CalcChargesOfStay() + CalcMiscCharges()))
End Function

使用Return关键字,function name设置为结果。

所以看起来像这样:

Function CalcChargesOfStay() As Decimal
    Return CDec(TextBoxLength.Text) * DayRate
End Function

Function CalctotalCharges() As Decimal
    Return CalcChargesOfStay() + CalcMiscCharges()
End Function

或者像这样:

Function CalcChargesOfStay() As Decimal
    CalcChargesOfStay = (CDec(TextBoxLength.Text) * DayRate)
End Function

Function CalctotalCharges() As Decimal
    CalctotalCharges = (CalcChargesOfStay() + CalcMiscCharges())
End Function

但是你不能同时使用这两种语法。