Discussion Locked

VB

0 helpful
1 reply
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

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

1 reply

by irina medvinskaya

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
lblTotal.Caption=lTotal

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.

This discussion is closed to new replies.