2012-09-14 45 views
0

我发现这对我来说非常困难。看到有2个lisbox。一个包含零售产品的价格,另一个包含零售产品的数量。如何将两个列表框的项目相乘并添加它们

enter image description here

,他希望用户可以添加尽可能多的项目。所以项目数量不受限制。我希望在添加新项目**时,**代码自动计算总现金。通过乘以其数量列表中的所有项目并添加它们。 请请帮帮我。 在此先感谢。

回答

1

最简单的解决方案是循环包含价格的列表框。数量指数等于价格指数。对?

' this holds the value for the total amount 
Dim totalAmount As Integer = 0 
' loops the listbox to all items 
For a As Integer = 0 To ListBox1.Items.Count - 1 
    totalAmount = totalAmount + (CInt(ListBox1.Items(a).ToString) * CInt(ListBox2.Items(a).ToString)) 
Next 
MsgBox(totalAmount) 
+0

你重复两次ListBox1中,我想你想指ListBox2了''标志;-) –

+0

@约翰佑 由于一吨了。工作很好! – Ubaada

相关问题