简体   繁体   English

如何将两个列表框的项目相乘并添加它们

[英]How to multiply items of two listbox and add them

There are 2 lisbox.有2个lisbox。 One contains the price of retail product and second contains the quantities of a retail product.一个包含零售产品的价格,第二个包含零售产品的数量。

在此处输入图片说明

The user can add as many items as he wants.用户可以根据需要添加任意数量的项目。 So the number of items is not limited.所以物品的数量没有限制。 I want that when a new item is added**,** code automatically calculates the Total Cash.我希望在添加新项目时**,** 代码会自动计算总现金。 By multiplying all the items from their quantity list and add them.通过将数量列表中的所有项目相乘并添加它们。 Thanks in Advance.提前致谢。

The simpliest solution is to loop the listbox the contains the price.最简单的解决方案是循环包含价格的列表框。 The index of quantity is equal to the index of price.数量指数等于价格指数。 Right?对?

' 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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM