0

can u pass an idea... is this is possible to plus all that items(Integer) that are in listbox or listview...
e.g a list box have 4 items...
1)-20
2)-40
3)-80
4)-100
is this possible to plus these items,??? items also can b infinite, depends upon user...i dont have any idea, and could not find thing regarding this on internet

3
Contributors
8
Replies
10
Views
5 Years
Discussion Span
Last Post by AndreRet
Featured Replies
  • 1

    [QUOTE]is this is possible to plus all that items(Integer) that are in listbox or listview...[/QUOTE] Yes, you can. For listbox : [CODE]Dim i, result As Integer For i = 0 To List1.ListCount result = result + List1.List(i) Next i MsgBox result[/CODE] For Listview : [CODE]Dim i, result As Integer For … Read More

1

is this is possible to plus all that items(Integer) that are in listbox or listview...

Yes, you can.

For listbox :

Dim i, result As Integer
For i = 0 To List1.ListCount
    result = result + List1.List(i)
Next i
MsgBox result

For Listview :

Dim i, result As Integer
For i = 1 To ListView2.ListItems.Count
    result = result + ListView2.ListItems(i).SubItems(1)
Next i
MsgBox result
0

The above code will not execute 100%. Add a minus 1 after the count -

For i = 0 To List1.ListCount - 1 'Here, otherwise it will skip the first record

For i = 1 To ListView2.ListItems.Count - 1 'Here as well...

:)

0

@ Andre : thanks for the correction about listbox (you right index in lisbox start with 0) but i'm not sure about listview. if you minus listitems.count with 1 then it will skip the last item when you adding the items.

Edited by Jx_Man: n/a

0

With a listview, you need to determine if there are headers or not, then deduct the header line and start reading from the following line.:)

0

Goooood......i had not headers,. thats why both codes of Jx were working fine without minus "-"....
Thanks Andre for Correction.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.