如何在Visual Basic中解决此过程和函数

时间:2012-03-02 20:41:07

标签: vb.net visual-studio-2010

我有这个家庭工作问题,我不知道我做错了有很多错误,我不知道如何纠正。这个问题:

自动化服务店执行以下服务(下面的所有服务都分配了一个值):

  • 换油
  • 润滑油工作
  • 散热器冲洗
  • Transmision flush inspection
  • 更换消声器和
  • 轮胎旋转

创建一个显示客户访问总数的应用程序。到目前为止,这是我的代码:

Public Class Form1
    'class level declerations
    Const decTax_Rate As Decimal = 0.06D ' TaX on Parts only
    Const decOilChange As Decimal = 26   ' cost of oil change
    Const decLubeJob As Decimal = 18     ' cost for lube job
    Const decRadiator As Decimal = 30    ' cost for Raditor Flush
    Const decTransmission As Decimal = 80 ' cost of transmission work
    Const decInspection As Decimal = 15   ' cost of inspection
    Const decReplaceMuffler As Decimal = 100 'cost of replacing muffler
    Const decRotateTire As Decimal = 20   'cost of rotating tire

End Class

Private Sub btnCalculate_Click(....) Handles btnCalculate.Click ( Error: Identify expected. I put in the following identifiers( Byval decpart as decimal and so on) but still underline the whole procedure as statement is not valid in a namespace)
    ' The procedure calculate the service total
    Dim decPart As Decimal            ' hold charges for parts
    Dim decServiceLabor As Decimal    ' hold charges for labor and other services
    Dim decTaxCharges As Decimal      ' hold sales tax on parts
    Dim decTotalCharges As Decimal    ' hold total charges


    decServiceLabor = OilLubeCharges() + FlushCharges() + MiscCharges() + OtherCharges()
    decPart = part1
    decTaxCharges = CalcTax(decParts)
    decTotalCharges = decOtherCharges + decTaxCharges

    lblServiceString.Text = decServiceLabor.ToString("c")
    lblParts.Text = decPart.ToString("c")
    lblPartsTax.Text = decTax_Rate.ToString("c")
    lblTotalFees.Text = decTotalCharges.ToString("c")
End Sub
Private Sub btnClear_Click(...) Handles btnClear.Click

    ' This procedur clears the controls to default values
    ClearOilLube()  ' Clear the check boxes for oil and Lube jobs
    ClearFlushes()  ' Clear the check boxes for radiation and transmission
    ClearsMisc()    ' Clear the check boxes for inspection muffler and tire
    ClearOther()    ' Clear the text boxes for parts and labor
    ClearFees()     ' Clear the summary lables

End Sub
Private Sub btnExit_Click(...) Handles btnExit.Click
    ' Close the form.
    Me.Close()
End Sub


Function OilLubeCharges(ByVal decOilChange As Decimal) As Decimal
    ' This function returns the charges for an oil change and or lube job.
    Dim decOilLube As Decimal = 0D
    If chkOilChange.Checked = True Then
        decOilLube += decOilChange
    End If

    If chkLubeJob.Checked = True Then
        decOilLube += decLubeJob
    End If
    Return decOilLube
End Function


Function MiscCharges(ByVal decInspection As Decimal) As Decimal
    'The function returns the total charges for an inspection, muffler replacement and/or a tire rotation
    Dim decMisc As Decimal = 0D
    If chkInspection.Checked = True Then
        decMisc += decInspection
    End If

    If chkReplaceMuffler.Checked = True Then
        decMisc += decReplaceMuffler
    End If

    If chkTireRotation.Checked = True Then
        decMisc += decRotateTire

    End If

    Return decMisc
End Function


Function FlushCharges(ByVal decRadiator As Decimal) As Decimal
    'This function return the total charges for a radiator flush and/or a tansmission flush
    Dim decFlush As Decimal = 0D
    If chkRadiatorFlush.Checked = True Then
        decFlush += decRadiator

    End If

    If chkTrasmission.Checked = True Then
        decFlush += decTransmission

    End If

    Return decFlush

End Function
Function Parts(ByVal decpart As Decimal) As Decimal
    '  To hold the parts sales
    Dim decPart1 As Decimal
    decPart1 += decpart

    Return decPart1


End Function
Function CalcTax(ByVal decpart As Decimal) As Decimal
    ' This Function receives the sales part and returns the sale part tax.
    Return decpart * decTax_Rate
End Function

Sub ResetOil()
    ' This procedure resets the oil and lube job.
    chkOilChange.Checked = False
    chkLubeJob.Checked = False
End Sub
Sub ResetMisc()
    ' This procedure resets the misc
    chkInspection.Checked = False
    chkReplaceMuffler.Checked = False
    chkTireRotate.Checked = False
End Sub
Sub ResetFlushFluids()
    ' This procedure resets the flush
    chkRadiatorFlush.Checked = False
    chkTrasmission.Checked = False
End Sub
Sub ResetPrice()
    ' This procedure resets the price
    lblServiceString.Text = String.Empty
    lblParts.Text = String.Empty
    lblPartsTax.Text = String.Empty
    lblTotalFees.Text = String.Empty

End Sub

实际上,所有函数的第一行都被加下划线作为无效的命名空间语句,并且即使在我输入Identify之后,所有过程都需要标识符。班级表格中没有任何错误。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

对于初学者,您需要确保Button个活动和Functions成为Form1班级的一部分。

Public Class Form1

    Private Sub btnCalculate_Click(sender As System.Object, e As System.EventArgs) Handles btnCalculate.Click

    End Sub

    Private Sub btnClear_Click(sender As System.Object, e As System.EventArgs) Handles btnClear.Click

    End Sub
End Class