Dictionary Help

HI,
I have tried to do calculating the value, the code seems to be fine, but the result is gone.

Listbox1.AddRow "A01","apple","2" Listbox1.AddRow "A01","apple","2" Listbox1.AddRow "A02","orange","2" Listbox1.AddRow "A02","orange","2" Listbox1.AddRow "A02","orange","2"

I am expecting the result

A01 apple 4 A02 orange 6

but the result is strange, the total is missing.

here is the code

[code] dim dictContent as new Dictionary

const col_code =0
const col_item = 1
const col_total = 2

for i as integer = 0 to ListBox1.ListCount-1
dim key as String = ListBox1.Cell(i,col_code)+";"+ListBox1.Cell(i,col_item)
if dictContent.HasKey(key) Then
dictContent.Value(key) = dictContent.Value(key).IntegerValue + Val(ListBox1.Cell(i,col_total))
else
dictContent.Value(key) = Val(ListBox1.Cell(i,col_total))
end
next

ListBox1.DeleteAllRows

for i as integer = 0 to dictContent.Count-1
dim key as String = dictContent.Key(i)
dim value as String = Str(dictContent.Value(key).IntegerValue)

ListBox1.AddRow(key.NthField(";",1),key.NthField(";",2),key.NthField(";",3),value)

next

[/code]

is there something that I have missed ? any help?

thanks
regards,
arief

In the For loop, your AddRow command is wrong. You are parsing out a non-existing 3rd value from the key and attempting to assign the actual value from the Dictionary to a non-existing 4th column in the ListBox.

Try this instead:

ListBox1.AddRow(key.NthField(";",1),key.NthField(";",2),value)