更新 VB.NET 时总值未更新

Total value not updating when I update VB.NET

用户在表单中输入他们想要的内容。例如,在零食中,用户想要 2 个汉堡,每个汉堡的价格为 160 - 以总价值显示。

总价值:

然后,用户改变了主意,决定要 6 个汉堡,而不是 2 个。点击“下订单”时,总价值仍然是 160。我希望当用户更改输入时该值会更新。我该如何解决这个问题?

(VB.NET)

Public Class Formpreceipt
    Dim party = Formrooms.txtparty.Text
    Dim partyy As Double
    Dim bday = Formrooms.txtbday.Text
    Dim bdayy As Double
    Dim vip = Formrooms.txtvip.Text
    Dim vipp As Double
    Dim deluxe = Formrooms.txtdeluxe.Text
    Dim deluxee As Double
    Dim fries = Formsnacks.txtfries.Text
    Dim friess As Double
    Dim burger = Formsnacks.txtburger.Text
    Dim burgerr As Double
    Dim cupcake = Formsnacks.txtcupcake.Text
    Dim cupcakee As Double
    Dim pizza = Formsnacks.txtpizza.Text
    Dim pizzaa As Double
    Dim icedtea = Formdrinks.txticedtea.Text
    Dim icedteaa As Double
    Dim soda = Formdrinks.txtsoda.Text
    Dim sodaa As Double
    Dim soju = Formdrinks.txtsoju.Text
    Dim sojuu As Double
    Dim beer = Formdrinks.txtbeer.Text
    Dim beerr As Double

    Private Sub Formpreceipt_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles btnplaceorder.Click
        partyy = party * 200
        bdayy = bday * 300
        vipp = vip * 400
        deluxee = deluxe * 500
        friess = fries * 40
        burgerr = Val(burger) * 80
        cupcakee = cupcake * 35
        pizzaa = pizza * 150
        icedteaa = icedtea * 20
        sodaa = soda * 35
        sojuu = soju * 80
        beerr = beer * 100

        txtotal.Text = "₱" & Format(partyy + bdayy + vipp + deluxee + friess + burgerr + cupcakee + pizzaa + icedteaa + sodaa + sojuu + beerr)
    End Sub
End Class

如果我读了你的代码,在 Button1_Click 你有 burgherr = burger * 80 首先,我建议你获取变量 burger 的值,例如 Val(burger) * 80 之后,在你的代码中我看不到你在哪里更新和使用总价值......我希望你有类似 TextBoxTotalValue.Text = burgherr.ToString()

您的设计还有改进的余地,但按照 user9938 的建议,将分配移至按钮的 Click() 事件。

变化:

partyy = party * 200
bdayy =  bday * 300
vipp = vip * 400
deluxee = deluxe * 500
friess = fries * 40
burgerr = burger * 80
cupcakee = cupcake * 35
pizzaa = pizza * 150
icedteaa = icedtea * 20
sodaa = soda * 35
sojuu = soju * 80
beerr = beer * 100

收件人:

partyy = Formrooms.txtparty.Text * 200
bdayy = Formrooms.txtbday.Text * 300
vipp = Formrooms.txtvip.Text * 400
deluxee = Formrooms.txtdeluxe.Text * 500
friess = Formsnacks.txtfries.Text * 40
burgerr = Formsnacks.txtburger.Text * 80
cupcakee = Formsnacks.txtcupcake.Text * 35
pizzaa = Formsnacks.txtpizza.Text * 150
icedteaa = Formdrinks.txticedtea.Text * 20
sodaa = Formdrinks.txtsoda.Text * 35
sojuu = Formdrinks.txtsoju.Text * 80
beerr = Formdrinks.txtbeer.Text * 100