好吧,我很难弄清楚我做错了什么。基本上我需要删除比平均数少的 Listbox1 项目,但它给了我:
System.ArgumentOutOfRangeException 未处理 Message=InvalidArgument='9' 的值对'index' 无效。参数名称:索引
Private Sub Label3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Label3.Click
Dim Myrand As New Random
Dim res As Double
Dim i As Integer
Dim n As Integer
Dim tot As Double
Dim avarage As Double
ListBox1.Items.Clear()
For i = 0 To 14 Step 1
res = Math.Round(Myrand.NextDouble, 3)
ListBox1.Items.Add(res)
tot = tot + res
Next
avarage = tot / ListBox1.Items.Count
MsgBox(avarage)
For i = 0 To ListBox1.Items.Count - 1 Step 1
If ListBox1.Items(i) < avarage Then
ListBox1.Items.RemoveAt(i)
n = n + 1
End If
Next
MsgBox("Removed " & n & " items!")
End Sub
有什么建议么?