简体   繁体   中英

How to multiply items of two listbox and add them

There are 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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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