2012-09-14 47 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

相關問題