SETAVG()子行的第7行出现错误,更全面的错误消息是类型' System.ArgumentOutOfRangeException'未处理的异常。发生在System.Windows.Forms.dll
中其他信息:InvalidArgument =' 0'的值不适用于' index'。
Private Sub setavrg_Click(sender As Object, e As EventArgs) Handles setavrg.Click
sortcol = 0
Call sortdata()
ListView1.Sorting = SortOrder.Ascending
Call setavg()
End Sub
Private Sub SETAVG()
ListView1.Sorting = SortOrder.None
Dim tmpitem As String
Dim tmpscore As Single = 0
Dim numcount As Single = 0
Dim i As Integer = -1
Dim myAVG As Single = 0
Dim lastitem As String = Me.ListView1.Items(0).Text
Dim lvi As ListViewItem
For Each lvi In ListView1.Items
i += 1
tmpitem = lvi.SubItems(0).Text
If tmpitem = lvi.SubItems(0).Text Then
myAVG = tmpscore / numcount
ListView1.Items(i - 1).SubItems(3).Text = myAVG.ToString
tmpscore = 0
numcount = 0
End If
Next
myAVG = tmpscore / numcount
ListView1.Items(i).SubItems(3).Text = myAVG.ToString
End Sub
答案 0 :(得分:0)
您的问题是ListView1.Items
使用的索引始于1
,而不是0
。您正在初始化i
= -1
然后执行i += 1
,因此,在第一次循环迭代中,i
将为0
。
尝试修改代码,以便在第一次循环迭代中i
为1
。