‘- 優雅的頽廢。 2019-07-09 11:46 采纳率: 50%
浏览 353
已结题

如何实现人员抽点的时候抽到指定人员,而不是随机人员。

单位有个竞赛活动,然后用PPT做了个人员抽点的小程序,需要最后控制人员抽点的顺序,抽到特定的人员,但是不知道怎么实现这个效果,现求助大佬。

Dim flag As Integer '全局变量用于查询是否按下停止键


Sub delay(T As Single)
  Dim time1 As Single
  time1 = Timer
  Do
     DoEvents
  Loop While Timer - time1 < T
End Sub


Private Sub 开始_Click()

flag = 0

'Dim StuData(500) As Person
'StuData() = 0
Dim StuData(500) As String
Dim buf As String
Dim i As Integer
i = 0



Open "E:\人员名册.txt" For Input As #1
'Open "E:\output.txt" For Output As #2

Do While Not EOF(1)
    Line Input #1, buf
    'Write #2, buf
    StuData(i) = buf
    i = i + 1

    '在循环中将姓名输入数组

Loop

'Close #1
'Close #2
Dim index As Integer
Dim tims As Integer
times = 0

'循环显示姓名1
Do Until (times > 65534 Or flag <> 0)

index = Int((i * Rnd) + 0)
Label1.Caption = StuData(index)
times = times + 1
delay (0.05)

Loop

Close #1

End Sub

Private Sub 停止_Click()
flag = 1

End Sub

用到的代码就是以上代码

图片说明

  • 写回答

2条回答 默认 最新

  • threenewbee 2019-07-09 11:52
    关注

    图片说明

    使用方法,编辑names文件,每个名字1行
    注意,需要抽取的人,名字后面加上一个空格
    不希望抽取的人,不要加
    则程序滚动的时候,所有人都参与滚动,停止的时候,有空格的才会出来

    Option Explicit
    
    Private isRunning As Boolean
    Dim names() As String
    
    Private Sub CommandButton1_Click()
        CommandButton1.Enabled = False
        Dim filecontent As String
        Open "names.txt" For Binary As #1
            filecontent = Input(LOF(1), #1)
        Close #1
        names = Split(filecontent, vbCrLf)
        Randomize
        isRunning = True
        While isRunning
            TextBox1.Text = RndName(False)
            DoEvents
        Wend
        TextBox1.Text = RndName(True)
        If TextBox1.Text = "" Then CommandButton1.Enabled = True: Exit Sub
        If Me.Application.ActivePresentation.Slides(2).Shapes(6).TextFrame.TextRange.Text <> "" Then Me.Application.ActivePresentation.Slides(2).Shapes(6).TextFrame.TextRange.Text = Me.Application.ActivePresentation.Slides(2).Shapes(6).TextFrame.TextRange.Text & ","
        Me.Application.ActivePresentation.Slides(2).Shapes(6).TextFrame.TextRange.Text = Me.Application.ActivePresentation.Slides(2).Shapes(6).TextFrame.TextRange.Text & TextBox1.Text
        CommandButton1.Enabled = True
    End Sub
    
    Private Function RndName(isSpec As Boolean) As String
        Dim cnt As Long
        cnt = 1
        Dim idx As Long
        Do
            cnt = cnt + 1
            If cnt > 99999 Then
                RndName = ""
                Exit Function
            End If
            idx = Int(Rnd * (UBound(names) - LBound(names) + 1)) + LBound(names)
            If Not IsExist(names(idx)) Then
                If isSpec Then
                    If (names(idx) <> Trim(names(idx))) Then
                        RndName = Trim(names(idx))
                        Exit Do
                    End If
                Else
                    RndName = Trim(names(idx))
                    Exit Do
                End If
            End If
        Loop
    End Function
    
    Private Function IsExist(name As String) As Boolean
        Dim arr() As String
        arr = Split(Me.Application.ActivePresentation.Slides(2).Shapes(6).TextFrame.TextRange.Text, ",")
        Dim i As Long
        For i = LBound(arr) To UBound(arr)
            If Trim(name) = Trim(arr(i)) Then
                IsExist = True
                Exit Function
            End If
        Next
        IsExist = False
    End Function
    
    Private Sub CommandButton2_Click()
        isRunning = False
    End Sub
    
    

    其他人如果也需要:https://download.csdn.net/download/caozhy/11311604

    评论

报告相同问题?

悬赏问题

  • ¥15 没有证书,nginx怎么反向代理到只能接受https的公网网站
  • ¥50 成都蓉城足球俱乐部小程序抢票
  • ¥15 yolov7训练自己的数据集
  • ¥15 esp8266与51单片机连接问题(标签-单片机|关键词-串口)(相关搜索:51单片机|单片机|测试代码)
  • ¥15 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多