Adding Numeric Values in a List Box

HI,

Can anyone point me in the right directions. I have a list box which can have 1 or many entries in it. These entries when added have a cost value also added:

Description | Cost | Date

Item1 10.00 1/1/0001
Item2 9.00 1/1/0001

Is there any script / method that can count the amount of entires adding the costs together to come out with a over all figure (e.g. 19.00)

Any help is really appreciated, thanks in advance

[code]Dim totalCost as Integer = 0
For i as Integer = 0 to Listbox1.ListCount-1
Dim rowCost as Integer = Listbox1.Cell( i , 1) // 1 because 2nd column is the cost
totalCost = totalCost + rowCost
next i

// and here you do whatever you want with the total cost.[/code]

Thanks Ashot,

Can i just check:

Dim rowCost as Integer = Listbox1.Cell( i , 1) // 1 because 2nd column is the cost

If i had 7 rows, and the cost was in the last, i assume that this would be:

Dim rowCost as Integer = Listbox1.Cell( i , 6)

The total cost i am going to put out in a msg box, so assuming i can do this:

msgbox totalcost

Yes, the column in your case would be 6 (since columns start from 0).

Also, since the totalCost is an Integer, you will have to convert it to a String first before showing it in a MsgBox. You can do that very easily: MsgBox Str(totalCost)

Thanks Ashot!

Hi,

When i trt to run this is get the following

Type missmatch error . expected int32 but got a string
Dim rowcost as integer = listbox1.cell(i,3)

Cam anyone help please?

Reason for i,3 as cost is now 4th column

Fixed it, needed to wrap

Dim rowcost as integer = val(listbox1.cell( i , 3))