Foxtable(狐表)用户栏目专家坐堂 → [求助]单个抽签的代码,如何更改?


  共有1382人关注过本帖树形打印复制链接

主题:[求助]单个抽签的代码,如何更改?

帅哥哟,离线,有人找我吗?
hrw68529
  1楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1111 积分:8577 威望:0 精华:0 注册:2012/7/10 9:09:00
[求助]单个抽签的代码,如何更改?  发帖心情 Post By: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()

 回到顶部
帅哥哟,离线,有人找我吗?
有点甜
  2楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:版主 帖子:85326 积分:427815 威望:0 精华:5 注册:2012/10/18 22:13:00
  发帖心情 Post By: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
  3楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1111 积分:8577 威望:0 精华:0 注册:2012/7/10 9:09:00
  发帖心情 Post By:2017/12/12 16:58:00 [只看该作者]

谢谢,非常好

 回到顶部
帅哥哟,离线,有人找我吗?
hrw68529
  4楼 | 信息 | 搜索 | 邮箱 | 主页 | UC


加好友 发短信
等级:五尾狐 帖子:1111 积分:8577 威望:0 精华:0 注册:2012/7/10 9:09:00
  发帖心情 Post By: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,谢谢


 回到顶部