Hi Hope you can help because its driving me up the wall.

I've made a program that can add 4 items in a row in a list box, for instance

Item Make Guarentee qty Price
toy car rover 1 1 £45.00
monkey monkey 2 1 £65.00

total: £100.00

The problem is I can't get the price to total up in a lable or textbox, however,
I can make it work if i seperate the box and make two, listbox1 for item,make,gtee, qty and listbox 2 for price only.

I don't want this because i want the row to delete in one go instead of deleting it from two boxes which is a time taker. code below

I've worked out how to delete and make it add up right its just the two boxes i cant get my head around.

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
Dim Model As String
Dim Make As String
Dim Guarantee As Integer = 0
Dim price As Double = 0
Dim qty As Integer = 0
Dim Discount As Double = 0
Dim DelCharge As Double = 0
Dim Subtotal As Double = 0
Dim total As Double = 0
Dim totalpayment As Double = 0

'find user input and assign values to their variables
Model = (ModelNotextbox.Text)
Make = (Maketextbox.Text)
Guarantee = Val(Guaranteecombobox.Text)
price = Val(Pricetextbox.Text)
qty = Val(Qtytextbox.Text)

'Price * qty
totalpayment = price * qty

'display data in list box
ListBox1.Items.Add(Model & ControlChars.Tab & ControlChars.Tab & Make & ControlChars.Tab & Guarantee & ControlChars.Tab & qty & ControlChars.Tab)

ListBox2.Items.Add(String.Format("{0:c}", totalpayment))

'Adds list box prices together *
Dim totals As Integer

For Each value As Double In ListBox2.Items
totals += value
Label28.Text = (String.Format("{0:c}", totals))

'Clear previous items

End Sub

Thanks alot for the help!


if you use 2 listboxs, put in the listbox click event

me.listbox1.index = me.listbox2.index

vice versa for the other one.

then do a loop for each listbox2 items adding the total, poor though

try using a listview, make 2 columns , car and price.
set the view to report, gridlines true (ms common controls 2.6 or 6.0)

with me .lstview1.listitems.add(,, "car")
.listsubitems.add,, "$1200.00"
end with

dim i as integer
i% = 0
do while i% <= me.lstview1.listitems.count
me.lstview1.listitems.item(i%).selected = true
me.label1.caption = me.label1.caption + replace$(me.lstview1.listitems.item(i%).listsubitems.item(2).text, "$", vbnullstring$)
i% = i% + 1

that should give you an idea, some of it might be wrong i have been using vb.net 08 listviews and they are a little different.

This article has been dead for over six months. Start a new discussion instead.