Web Development

General discussion



By waleed.f ·
VB beginner needs help: I am trying to calcualte an invoice total and generate an invoice number for each invoice processed. my items info are loaded from a text file into list boxes. I am getting my items' price from a listbox name lstSalesPrice. Ineed the lblTotal to display one final total of all the prices listed in that listbox If I delete an item from the listbox, the lblTotal should show the reduction in the total. Can you please help. It is an emergency. This question has already been posted but I need to have answer as soon as possible.

Thank you

This conversation is currently closed to new comments.

Thread display: Collapse - | Expand +

All Comments

Collapse -


by Irina Medvinskaya In reply to VB

1. Create a variable i to be used in a loop.
2. Create a variable iTotal to hold the total sum
3. Loop through all items in the list box and adding them up into iTotal.
4. Your code should look like this:

Dim i as Integer
Dim lTotal as Long
For i = 0 To lstSalesPrice.ListCount - 1
lTotal = lTotal + lstSalesPrice.List(i)
Next i

5. Your label will show the updated total every time.
6. You can add the above code to the click event of the command button on which a user clicks to delete an item from the list box. Just make sure you put it at the very end after the item is deleted.

Related Discussions

Related Forums