嗯,我有一些困难,搞清楚我做错了什么。 基本上我需要删除未满avarage listBox1中的项目,但它给我:Visual basic 2010从列表框中删除
System.ArgumentOutOfRangeException了未处理 消息= 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
有什么建议吗?
是的,这是赶上...谢谢! – enflam3
@ enflam3很高兴为您提供帮助 –