[英]How to get selected items from checked list box and compute their total
这是我的设计界面的图像:设计界面
我希望用户进行选择并输入他们希望购买的数量,然后一旦完成并按计算,它会根据输入的数量给出所选项目的总数,并在价格文本框中输入该总数。
这是我的代码......我被卡住了......
Private Sub btnExit_Click(sender As Object, e As EventArgs) Handles btnExit.Click
Me.Close()
End Sub
Public Sub frmDrinks_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Public Sub btnCalculate_Click(sender As Object, e As EventArgs) Handles btnCalculate.Click
Dim tMango As Integer
Dim tOrange As Integer
Dim tStrawberry As Integer
Dim tWatermelon As Integer
Dim tMinty As Integer
Dim tCoke As Integer
Dim tDiet As Integer
Dim tSprite As Integer
Dim tMineral As Integer
Dim tSpark As Integer
Dim tManSmooth As Integer
Dim tBanSmooth As Integer
Dim tTropSmooth As Integer
Dim tStrawSmooth As Integer
Dim tVanilla As Integer
Dim tCookie As Integer
Dim tManShake As Integer
Dim tBanShake As Integer
tMango = txtMango.Text
tOrange = txtOrange.Text
tStrawberry = txtStrawberry.Text
tWatermelon = txtWatermelon.Text
tMinty = txtMinty.Text
tCoke = txtCoke.Text
tDiet = txtDiet.Text
tSprite = txtSprite.Text
tMineral = txtMineral.Text
tSpark = txtSparkling.Text
tManSmooth = txtMansmooth.Text
tBanSmooth = txtBanana.Text
tTropSmooth = txtTropical.Text
tStrawSmooth = txtStrawSmooth.Text
tVanilla = txtVanilla.Text
tCookie = txtChipCookie.Text
tManShake = txtManShake.Text
tBanShake = txtBanShake.Text
Dim TotalSum As Double = 0
If Me.chkJuices.Items().ToString = "Mango" Then
TotalSum += (100 * tMango)
End If
If Me.chkJuices.Items().ToString = "Orange" Then
TotalSum += (100 * tOrange)
End If
If Me.chkJuices.Items().ToString = "Strawberry" Then
TotalSum += (100 * tStrawberry)
End If
If Me.chkJuices.Items().ToString = "Watermelonade" Then
TotalSum += (100 * tWatermelon)
End If
If Me.chkJuices.Items().ToString = "Minty Pineade" Then
TotalSum += (100 * tMinty)
End If
txtJuice.Text = TotalSum
End Sub
单击按钮时,您必须查看选中的复选框,然后进行适当的数学运算
Private Sub Calculate() Handles Button.click
Dim TotalSum As Double = 0
For i = 0 To (CheckedListBox1.Items.Count - 1)
If CheckedListBox1.GetItemChecked(i) = True Then
If CheckedListBox1.Items(i).ToString = "Mango" Then
TotalSum += (100 * tMango)
End If
If CheckedListBox1.Items(i).ToString = "Orange" Then
TotalSum += (100 * tOrange)
End If
End If
Next
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.