我的程序不会计算总数

时间:2015-02-04 17:13:30

标签: vb.net

我正在做一个学校项目,我应该创建一个计算租赁设备的数据库。它应该计算天数并计算整个账单的总数。我的程序没有计算。 这是该程序的代码:

Public Class VandemanForm

    ' Declare module level variables and constants.

    Const FLOOR_POLISHER_PER_DAY_Decimal As Decimal = 25.95D
    Const CARPET_STRETCHER_PER_DAY_Decimal As Decimal = 17.95D
    Const NAIL_GUN_PER_DAY_Decimal As Decimal = 11.49D
    Const AIR_COMPRESSOR_PER_DAY_Decimal As Decimal = 19.95D

    'This stores the price per day

    Private FloorPolisherPerDayDecimal As Decimal = 0D
    Private CarpetStretcherPerDayDecimal As Decimal = 0D
    Private NailGunPerDayDecimal As Decimal = 0D
    Private AirCompressorPerDayDecimal As Decimal = 0D

    'This stores the number of days entered

    Private FloorPolisherDaysDecimal As Decimal = 0D
    Private CarpetStretcherDaysDecimal As Decimal = 0D
    Private NailGunDaysDecimal As Decimal = 0D
    Private AirCompressorDaysDecimal As Decimal = 0D

    Private Sub CalculateButton_Click(ByVal sender As  _
        System.Object, ByVal e As System.EventArgs) _
        Handles CalculateButton.Click

        ' Declare procedure level variables to hold data

        Dim FloorPolisherTotalDecimal As Decimal = 0D
        Dim CarpetStretcherTotalDecimal As Decimal = 0D
        Dim NailGunTotalDecimal As Decimal = 0D
        Dim AirCompressorTotalDecimal As Decimal = 0D
        Dim GrandTotalDecimal As Decimal = 0D

        ' Check to see that data has been entered and in
        ' the correct format before calculating totals.

        If FirstNameTextBox.Text <> vbNullString And _
            LastNameTextBox.Text <> vbNullString Then
        Else
            MessageBox.Show("First name and last name must be entered.", _
                       "Customer name error.", MessageBoxButtons.OK, _
                       MessageBoxIcon.Error)
            FirstNameTextBox.Focus()
        End If

        ' Check for an entry in the equipment days text boxes and if not
        ' empty, go on to calculate

        Try

            If FloorPolisherDaysTextBox.Text <> vbNullString Then
                FloorPolisherDaysDecimal = Decimal.Parse(FloorPolisherDaysTextBox.Text)
                FloorPolisherTotalDecimal = FloorPolisherDaysDecimal * FloorPolisherPerDayDecimal

            End If

            If CarpetStretcherDaysTextBox.Text <> vbNullString Then
                CarpetStretcherDaysDecimal = Decimal.Parse(CarpetStretcherDaysTextBox.Text)
                CarpetStretcherTotalDecimal = CarpetStretcherDaysDecimal * CarpetStretcherPerDayDecimal
            End If

            If NailGunDaysTextBox.Text <> vbNullString Then
                NailGunDaysDecimal = Decimal.Parse(NailGunDaysTextBox.Text)
                NailGunTotalDecimal = NailGunDaysDecimal * NailGunPerDayDecimal
            End If

            If AirCompressorDaysTextBox.Text <> vbNullString Then
                AirCompressorDaysDecimal = Decimal.Parse(AirCompressorDaysTextBox.Text)
                AirCompressorTotalDecimal = AirCompressorDaysDecimal * AirCompressorPerDayDecimal

            End If

            GrandTotalDecimal = FloorPolisherTotalDecimal + CarpetStretcherTotalDecimal _
                + NailGunTotalDecimal + AirCompressorTotalDecimal

        Catch ex As Exception
            MessageBox.Show("The days of the equipment rental must be numeric if entered.",
                             "Data Entry Error", MessageBoxButtons.OK, MessageBoxIcon.Error)

        End Try

        ' Display the results and format as currency
        FloorPolisherSubtotalTextBox.Text = FloorPolisherTotalDecimal.ToString("C")
        CarpetStretcherSubtotalTextBox.Text = CarpetStretcherTotalDecimal.ToString("C")
        NailGunSubtotalTextBox.Text = NailGunTotalDecimal.ToString("C")
        AirCompressorSubtotalTextBox.Text = AirCompressorTotalDecimal.ToString("C")

        GrandTotalDecimal = FloorPolisherTotalDecimal + CarpetStretcherTotalDecimal _
            + NailGunTotalDecimal + AirCompressorTotalDecimal
        TotalTextBox.Text = GrandTotalDecimal.ToString("C")


    End Sub

    Private Sub ExitButton_Click(ByVal sender As  _
         System.Object, ByVal e As System.EventArgs) _
         Handles ExitButton.Click

        Me.Close()

    End Sub

    Private Sub ClearButton_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles ClearButton.Click

        ' Clear all text boxes, Return the focus to the first name field.

        FirstNameTextBox.Clear()
        LastNameTextBox.Clear()
        FloorPolisherDaysTextBox.Clear()
        CarpetStretcherDaysTextBox.Clear()
        NailGunDaysTextBox.Clear()
        AirCompressorDaysTextBox.Clear()
        FloorPolisherSubtotalTextBox.Clear()
        CarpetStretcherSubtotalTextBox.Clear()
        NailGunSubtotalTextBox.Clear()
        AirCompressorSubtotalTextBox.Clear()
        TotalTextBox.Clear()

        'Return focus to the first name textbox
        FirstNameTextBox.Focus()

    End Sub

    Private Sub OrderGroupBox_Enter(sender As System.Object, e As System.EventArgs) Handles FloorToolOrderGroupBox.Enter

    End Sub
End Class

1 个答案:

答案 0 :(得分:0)

我认为你最好把不同物品的价格加入。表单上没有这些位置,类变量都包含零值。