嗯,我有一些困難,搞清楚我做錯了什麼。 基本上我需要刪除未滿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很高興爲您提供幫助 –