Vba Windows窗体应用程序如何从列表框添加项目
我有一个任务来创建一个简单的快餐点餐系统,我成功地为列表框中的项目分配了值,但是每次我按下按钮下订单时,它并不总是将所选项目相加Vba Windows窗体应用程序如何从列表框添加项目,vba,Vba,我有一个任务来创建一个简单的快餐点餐系统,我成功地为列表框中的项目分配了值,但是每次我按下按钮下订单时,它并不总是将所选项目相加 Public Class FastFoodPizza Dim cheesepizza, pepperonipizza, meatpizza, margheritapizza, bbqchickenpizza As Decimal Dim thinbase, thickbase As Decimal Dim large, medium, small As Decimal
Public Class FastFoodPizza
Dim cheesepizza, pepperonipizza, meatpizza, margheritapizza, bbqchickenpizza As Decimal
Dim thinbase, thickbase As Decimal
Dim large, medium, small As Decimal
Dim total As Decimal
Private Sub LtbPizzChoices_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ltbPizzChoices.SelectedIndexChanged
ltbPizzChoices.SelectionMode = SelectionMode.MultiSimple
End Sub
Private Sub GrbBase_Enter(sender As Object, e As EventArgs) Handles grbBase.Enter
End Sub
Private Sub BtnPlaceorder_Click(sender As Object, e As EventArgs) Handles btnPlaceorder.Click
For Each item As String In ltbPizzChoices.SelectedItems
If item = "Cheese Pizza" Then
cheesepizza = 7.99
End If
If item = "Pepperoni Pizza" Then
pepperonipizza = 8.99
End If
If item = "Meat Pizza" Then
meatpizza = 9.49
End If
If item = "Margherita Pizza" Then
margheritapizza = 7.49
End If
If item = "BBQ Chicken Pizza" Then
bbqchickenpizza = 10.5
End If
Next
txtTotal.Text = (cheesepizza + pepperonipizza + meatpizza + margheritapizza + bbqchickenpizza)
End Sub
Private Sub TxtTotal_TextChanged(sender As Object, e As EventArgs) Handles txtTotal.TextChanged
End Sub
下课我想我们不是来帮你做作业的,但是 您的代码可能会将
txtotal.Text
的值设置为仅最近的选择,而不是与以前的选择相符(如果这是您的目标),因为(猜测)您的列表框可能设置为单一选择
您(可能)需要设置一个静态或模块变量来保存单个选择和订单总数
有许多方法可以改进您的代码:
Case Select
而不是multipleIf
stxtotal.TextChanged
处理程序