以文本方式查看主题

-  Foxtable(狐表)  (http://www.foxtable.com/bbs/index.asp)
--  专家坐堂  (http://www.foxtable.com/bbs/list.asp?boardid=2)
----  [求助]单个抽签的代码,如何更改?  (http://www.foxtable.com/bbs/dispbbs.asp?boardid=2&id=110898)

--  作者:hrw68529
--  发布时间:2017/12/12 7:58:00
--  [求助]单个抽签的代码,如何更改?
以下代码是批量抽签,现在是想写一段单个抽签的代码,要求是:当选中一行后,只抽一个号,放在面试顺序列中,当再选中另一行后,还是只抽一个签,但原来已抽过的号,不再抽取,保证唯一,如何实现?谢谢

Dim cr2 As Row = Tables("人员抽取_人员").current
If cr2.IsNull("面试顺序") = False Then
    MessageBox.Show("已抽签完毕,不能再抽取!","温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    Return
End If

Dim dt As Table = Tables("人员抽取_人员")
Dim cnt As Integer = dt.Rows.Count
Dim ids(cnt -1) As Integer
For i As Integer = 0 To cnt -1
    ids(i) = i
Next
For i As Integer = 0 To cnt \\ 2 \'洗牌次数
    Dim id1 As Integer = rand.Next(0,cnt)
    Dim id2 As Integer = rand.Next(0,cnt)
    Dim vid As Integer = ids(id1)
    ids(id1) = ids(id2)
    ids(id2) = vid
Next
dt.StopRedraw()
For i As Integer = 0 To Tables("人员抽取_人员").Rows.count -1
    Tables("人员抽取_人员").Rows(i)("面试顺序")=ids(i)+1
Next
dt.ResumeRedraw()
Tables("人员抽取_人员").save()

--  作者:有点甜
--  发布时间:2017/12/12 9:05:00
--  

Dim cr2 As Row = Tables("人员抽取_人员").current
If cr2.IsNull("面试顺序") = False Then
    MessageBox.Show("已抽签完毕,不能再抽取!","温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    \'Return
End If


Dim dt As Table = Tables("人员抽取_人员")
Dim ids As new List(of Integer)
For Each r As Row In dt.rows
    ids.Add(r.Index)
Next
For Each r As Row In dt.rows
    If r.IsNull("面试顺序") = False Then
        ids.Remove(r("面试顺序"))
    End If
Next
Dim cnt = ids.count
\'For i As Integer = 0 To cnt \\ 2 \'洗牌次数
    \'Dim id1 As Integer = rand.Next(0,cnt)
    \'Dim id2 As Integer = rand.Next(0,cnt)
    \'Dim vid As Integer = ids(id1)
    \'ids(id1) = ids(id2)
    \'ids(id2) = vid
\'Next

\'随机取一个
cr2("面试顺序") =ids(rand.Next(0, ids.count))


--  作者:hrw68529
--  发布时间:2017/12/12 16:58:00
--  
谢谢,非常好
--  作者:hrw68529
--  发布时间:2017/12/12 16:59:00
--  

Dim cr2 As Row = Tables("人员抽取_人员").current
If cr2.IsNull("面试顺序") = False Then
    MessageBox.Show("已抽签完毕,不能再抽取!","温馨提示", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
    Return
End If


Dim dt As Table = Tables("人员抽取_人员")
Dim ids As new List(of Integer)
For Each r As Row In dt.rows
    ids.Add(r.Index+1)
Next
For Each r As Row In dt.rows
    If r.IsNull("面试顺序") = False Then
        ids.Remove(r("面试顺序"))
    End If
Next
Dim cnt = ids.count

cr2("面试顺序") =ids(rand.Next(0, ids.count-1))

修改后的代码,可以不生成0,谢谢