改一下,如下代码
Dim c As Integer
Dim ilist As new List(of Integer)
Dim drs As List(Of DataRow) = DataTables("表").Select("是否道路 = true")
Do While c < 2000
Dim i As Integer = Rand.Next(0,drs.count-1)
If ilist.Contains(drs(i)("_Identify"))=False AndAlso (c+drs(i)("套数"))<2050 Then
ilist.Add(drs(i)("_Identify"))
c= c+drs(i)("套数")
End If
Loop
Dim ids As String
For Each i As Integer In ilist
ids = ids & "," & i
Next
Tables("新区").Filter="_Identify in (" & ids.trim(",") & ")"
MessageBox.show("抽选后的套数为: " & Tables("新区").Compute("sum(套数)"))