计算仅在食品订购表格上执行一次(VB)

时间:2015-12-16 02:54:22

标签: vb.net forms

我正在制作食物订购表格,我在计算方面遇到了麻烦。每次订购热狗时,表格都应该将成本加到总金额上,所以一个热狗是2美元,再添加另一个热卖4美元,等等。但它只执行一次计算,所以无论多少项我添加订单价格保持不变,好像我只订购了一个。

我在运行时没有收到任何错误,所以它必定是一个逻辑错误。这是完整的代码。我不知道此时我应该提供哪些其他信息。感谢所有帮助。

Public Class DroneDogs

Dim DogChoice As String
Dim condiment1 As String
Dim condiment2 As String
Dim condiment3 As String

Const DBL_TAX_RATE As Double = 0.07
Const DBL_DRONE_DOG As Double = 1.99

Dim intNumDog As Integer

Dim dblSubTotal As Double
Dim dblSalesTax As Double
Dim dblTotalCost As Double





Private Sub btnAddCustomer_Click(sender As Object, e As EventArgs) Handles btnAddCustomer.Click

    cboCurrentCustomers.Items.Add(txtAddCustomer.Text)

End Sub

Private Sub optBeef_CheckedChanged(sender As Object, e As EventArgs) Handles optBeef.CheckedChanged
    If (optBeef.Checked) Then
        DogChoice = "Beef Dog"

    End If


End Sub

Private Sub optPork_CheckedChanged(sender As Object, e As EventArgs) Handles optPork.CheckedChanged
    If (optPork.Checked) Then
        DogChoice = "Pork Dog"

    End If


End Sub

Private Sub optTurkey_CheckedChanged(sender As Object, e As EventArgs) Handles optTurkey.CheckedChanged
    If (optTurkey.Checked) Then
        DogChoice = "Turkey Dog"


    End If


End Sub


Private Sub chkKetchup_CheckedChanged(sender As Object, e As EventArgs) Handles chkKetchup.CheckedChanged


    If (chkKetchup.Checked) Then
        condiment1 = " + Ketchup"
    Else
        condiment1 = Nothing
    End If

End Sub

Private Sub chkMustard_CheckedChanged(sender As Object, e As EventArgs) Handles chkMustard.CheckedChanged

    If (chkMustard.Checked) Then
        condiment2 = " + Mustard"
    Else
        condiment2 = Nothing
    End If

End Sub

Private Sub chkRelish_CheckedChanged(sender As Object, e As EventArgs) Handles chkRelish.CheckedChanged

    If (chkRelish.Checked) Then
        condiment3 = " + Relish"
    Else
        condiment3 = Nothing
    End If

End Sub



Private Sub btnAddDog_Click(sender As Object, e As EventArgs) Handles btnAddDog.Click



    intNumDog = +1
    dblSubTotal = intNumDog * DBL_DRONE_DOG
    dblSalesTax = dblSubTotal * DBL_TAX_RATE
    dblTotalCost = dblSubTotal + dblSalesTax

    txtSub.Text = dblSubTotal.ToString("c2")
    txtTax.Text = dblSalesTax.ToString("c2")
    txtTotal.Text = dblTotalCost.ToString("c2")



    Dim addCondiment As String = condiment1 + condiment2 + condiment3

    If (DogChoice = "Beef Dog") Or
        (DogChoice = "Pork Dog") Or
        (DogChoice = "Turkey Dog") Then
        lstOrder.Items.Add(DogChoice + addCondiment + ": " + txtTotal.Text)
    Else
        MsgBox("Please select a Hot Dog type.")
    End If


End Sub


Private Sub btnClearOrder_Click(sender As Object, e As EventArgs) Handles btnClearOrder.Click

    lstOrder.Items.Clear()

    txtSub.Clear()
    txtTax.Clear()
    txtTotal.Clear()

    chkKetchup.Checked = 0
    chkMustard.Checked = 0
    chkRelish.Checked = 0

    optBeef.Checked = 0
    optPork.Checked = 0
    optTurkey.Checked = 0

End Sub

Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click

    'Exits the program
    If MessageBox.Show("Do you want to exit the DroneDogs application?", "DroneDogs",
     MessageBoxButtons.YesNo, MessageBoxIcon.Question) _
     = DialogResult.Yes Then
        Application.Exit()
    End If

End Sub


Private Sub btnOrderComplete_Click(sender As Object, e As EventArgs) Handles btnOrderComplete.Click

    Receipt.Show()

End Sub

Private Sub btnRemoveDog_Click(sender As Object, e As EventArgs) Handles btnRemoveDog.Click
    lstOrder.Items.Remove(lstOrder.SelectedItem)
End Sub

结束班

1 个答案:

答案 0 :(得分:1)

我认为问题在于行

intNumDog = +1

在此行中,您始终将intNumDog设置为+1值。这与:

相同
intNumDog = 1

您想要为intNumDog

的值添加一个
intNumDog += 1