试试
DataTables("对阵表").DataRows.Clear
Dim bsrq As WinForm.DateTimePicker = e.Form.Controls("rq")
Dim qsmc As WinForm.ComboBox = e.Form.Controls("棋赛名称")
Dim di1 As String = qsmc.Value
Dim m As WinForm.TextBox = e.Form.Controls("第几轮")
Dim di2 As Integer = m.Value = 1
Dim di3 As Date = bsrq.Value
Dim ds As DataRow = DataTables("对阵表").SQLfind("棋赛名称 = '" & di1 & "' And 第几轮比赛 = '" & di2 & "'")
If ds Is Nothing Then
ds = DataTables("对阵表").addnew
ds("桌号") = 0
End If
Dim di4 As Integer = ds("桌号")
Dim dr As DataRow = DataTables("比赛积分").SQLfind("棋赛名称 = '" & di1 & "'")
If dr Is Nothing Then
Dim ls As Integer = DataTables("基本信息").SQLGetValues("棋赛名称|姓名|身份", "棋赛名称 = '" & di1 & "' And 姓名 is not null and 身份 = '参赛人'").Count
Dim ids1,ids2 As New List(of Integer) '用于存储洗牌前后的位置
For i As Integer = 0 To ls -1 '准备初始的牌
ids1.add(i)
Next
For i As Integer = 0 To ls - 1 '开始洗牌
Dim idx As Integer = ids1(rand.Next(0,ids1.count))
ids2.Add(idx)
ids1.Remove(idx)
Dim n = 2
If ls > = n Then
Dim ls1 As new List(Of String)
Do While ls1.count < n
Dim a = Rand.Next(0, ls)
If ls1.Contains(a) = False Then
ls1.add(ids2(a))
End If
Loop
di4 = di4 + 1
if ls1.count > 0 then ds("红方_编号") = ls1(0)
if ls1.count > 1 then ds("黑方_编号") = ls1(1)
End If
Next
End If
DataTables("对阵表").Save()
[此贴子已经被作者于2020/4/10 14:36:36编辑过]