The Listview in .NET is 0-based (VB6 is 1-based), so if you have 53 items, then loop from 0 to 52. ListView1.Items.Count will return 53, which means you're looping from 0 to 53 and index 53 doesn't exist.
You don't have to do "intRptTotal = intRptTotal + ....", but you can do "intRptTotal += ..." instead.
vb.net Code:
Dim intRptTotal As Integer = 0 For i As Integer = 0 To lvwReportCount.Items.Count - 1 intRptTotal += CInt(lvwReportCount.Items(i).SubItems(1).Text) Next
Alternatively, you can also do a for each loop.
vb.net Code:
For Each lvw As ListViewItem In lvwReportCount.Items intRptTotal += CInt(lvw.SubItems(1).Text) Next




Reply With Quote