【问题标题】:How to multiply items of two listbox and add them如何将两个列表框的项目相乘并相加
【发布时间】:2020-06-23 21:25:33
【问题描述】:

有 2 个 lisbox。第一个包含零售产品的价格,第二个包含零售产品的数量。

用户可以根据需要添加任意数量的项目。所以物品的数量不受限制。我希望在添加新项目时**,**代码自动计算总现金。通过将数量列表中的所有项目相乘并添加它们。 提前致谢。

【问题讨论】:

    标签: vb.net listbox


    【解决方案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)
    

    【讨论】:

    • 你重复 ListBox1 两次,我想你想在 * 符号之后引用 ListBox2 ;-)
    • @John Woo 非常感谢。工作得很好!
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-04-25
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多