我把代码这么改了一下并增加了一个自定义函数testcount
Dim count As Integer = 0
Dim Names As List(Of Integer) = Args(0)
Dim Val As Integer = Args(1)
For t As Integer = 0 To (Names.Count-1)
If Names.Contains(Val)= True Then
count = count+1
End If
Next
Return count
光星期一测试没问题,加上别的星期就卡住了
Dim lst100 As new List(of Integer)
Dim lst200 As new List(of Integer)
For Each dr As DataRow In DataTables("表b").DataRows
Select Case dr("星期")
Case "星期一"
dr("假期")="1,2"
Dim ids1 As String
Dim lst1 As new List(of Integer)
Dim lst11 As new List(of Integer)
Dim v1() As Integer = {1,2,3,4,5,6,7,8,9,10}
lst11.AddRange(v1)
lst1.Add(1)
lst1.Add(2)
lst11.Remove(1)
lst11.Remove(2)
Do While lst1.count < 4
Dim id As Integer = rand.Next(1,10)
If lst1.Contains(id) = False And Functions.Execute("testcount",lst100,id) < 6 Then
lst1.Add(id)
lst100.Add(id)
lst11.Remove(id)
ids1 = ids1 & id & ","
End If
Loop
dr("晚班")= ids1.Trim(",")
ids1 = ""
Do While lst1.count < 5
Dim id As Integer = rand.Next(1,10)
If lst1.Contains(id) = False And Functions.Execute("testcount",lst200,id) < 3 Then
lst1.Add(id)
lst200.Add(id)
lst11.Remove(id)
ids1 = ids1 & id & ","
End If
Loop
dr("早班")= ids1.Trim(",")
ids1 = ""
For t As Integer = 0 To (lst11.Count-1)
ids1 = ids1 & lst11(t) & ","
Next
dr("正常班")= ids1.Trim(",")
ids1 = ""
lst1.Clear
lst11.Clear
lst1.Add(1)
lst1.Add(2)
lst11.Remove(1)
lst11.Remove(2)