找回密码
 立即注册
搜索
楼主: wqpwjw

PPT抽奖程序

32
回复
10063
查看
[复制链接]

3

主题

6

帖子

88

幻币

一流武者

Rank: 3Rank: 3

积分
322
QQ
2017-2-6 19:43:22 显示全部楼层
混沌之下,还是焕然一新了:
213823qgflqqoqzf9xghfh.jpg

限制性抽奖并汇集抽奖结果-h.rar (76.9 KB, 下载次数: 154)
PPT学习论坛
回复 支持 反对

使用道具 举报

1

主题

11

帖子

33

幻币

江湖少侠

Rank: 2

积分
160
QQ
2017-2-6 19:46:04 显示全部楼层

  • Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) '参数是长整形(毫秒数)。Lib “kernel32”标明这个函数是引用kernel32.dll提供的函数。Kernel32.dll是windows的四个核心库之一。是用来延时n毫秒的
  • Dim s As New Collection, f As Boolean, j%, n%, temp, prr, frr, orr, nrr, jt$                                 '接受函数返回数组的temp不能 As String
  • Private Sub CommandButton1_Click()
  • Dim i%, r%
  • If j = 0 Then
  •    Set s = Nothing
  •    Dim app  As Object, xl As Object, m%, arr, xrr, ar, brr(200)
  •    Set app = CreateObject("Excel.Application")   '从excel提取数据
  •    Set xl = app.workbooks.Open(ActivePresentation.Path & "限制性抽奖设置-h.xls")
  •    ScreenUpdating = False                        'ppt中禁止使用application.ScreenUpdating = False
  •    app.Visible = False                           '调试时True确保不隐藏excel窗口
  •    With xl.Worksheets("基础数据")                '不能用xl.sheet2
  •         m = .[iv1].End(1).Column - 2
  •         arr = .[c1].resize(1, m)
  •         prr = .[c3].resize(1, .[iv3].End(1).Column - 2)
  •         frr = .[c4].resize(1, .[iv4].End(1).Column - 2)
  •         orr = .[c5].resize(1, .[iv5].End(1).Column - 2)
  •         nrr = .[c6].resize(1, .[iv6].End(1).Column - 2)
  •         xrr = .[c7].resize(3, m)
  •    End With
  •    app.Visible = True
  •    xl.Close False:       app.Quit
  •    Set xl = Nothing: Set app = Nothing
  •    For Each ar In xrr                            'xrr的滤除号码整理为一维数组brr,以便使用filter
  •        If ar <> &quot;&quot; Then brr(k) = ar: k = k + 1
  •    Next
  •    k = 0
  •    For i = 1 To m                                '抽奖号码条件滤除
  •        If UBound(Filter(brr, arr(1, i))) < 0 Then s.Add arr(1, i), CStr(arr(1, i))
  •    Next
  •    Erase xrr: Set ar = Nothing: Erase arr: Erase brr   'Erase可代替Set= Nothing,但也不能用于变量
  •    j = 1                                         '抽奖序次初始化
  •    TextBox4.Text = &quot;三等奖&quot;                      '抽奖界面初始化
  •    Me.Shapes(&quot;TextBox 14&quot;).Visible = True        '可以用me替代ActivePresentation.Slides(1),好爽!
  •    Me.Shapes(&quot;TextBox 15&quot;).Visible = True
  •    Me.Shapes(&quot;TextBox 16&quot;).Visible = True
  •    Me.Shapes(&quot;TextBox 17&quot;).Visible = True
  •    Me.Shapes(&quot;TextBox 14&quot;).TextFrame.TextRange.Text = &quot;三等奖&quot;
  •    Me.Shapes(&quot;TextBox 15&quot;).TextFrame.TextRange.Text = &quot;二等奖&quot;
  •    Me.Shapes(&quot;TextBox 16&quot;).TextFrame.TextRange.Text = &quot;一等奖&quot;
  •    Me.Shapes(&quot;TextBox 17&quot;).TextFrame.TextRange.Text = &quot;特等奖&quot;
  • End If
  • f = False
  • If Me.CommandButton1.Caption = &quot;停止&quot; Then
  •    Me.CommandButton1.Caption = &quot;开始&quot;
  •    f = True
  • Else
  •    Me.CommandButton1.Caption = &quot;停止&quot;
  •    If j < 5 Then n = --Mid(3321, j, 1) Else n = 0 '抽取各奖等的个数;抽取特别奖置0
  •    Do
  •       If f Then
  •          Select Case j                            '操作汇奖区
  •                 Case 1
  •                      Me.TextBox5.Text = temp(0) & &quot;   &quot; & temp(1) & &quot;   &quot; & temp(2)
  •                      Me.TextBox5.Visible = True
  •                      jt = &quot;三等奖          &quot; & TextBox5.Text
  •                      Sleep 80                     '延时让抽中号码有机会显示在抽奖区,而非一闪而过飘到汇奖区;调试时可改为800观察
  •                      Me.TextBox1.Text = &quot;&quot;        '注意加me,因为slide7也有TextBox;否则会出现清除失效!
  •                      Me.TextBox2.Text = &quot;&quot;
  •                      Me.TextBox3.Text = &quot;&quot;
  •                 Case 2
  •                      Me.TextBox6.Text = temp(0) & &quot;   &quot; & temp(1) & &quot;   &quot; & temp(2)
  •                      Me.TextBox6.Visible = True
  •                      jt = &quot;二等奖          &quot; & TextBox6.Text & vbCrLf & jt
  •                      Sleep 80
  •                      Me.TextBox1.Text = &quot;&quot;
  •                      Me.TextBox2.Text = &quot;&quot;
  •                      Me.TextBox3.Text = &quot;&quot;
  •                 Case 3
  •                      Me.TextBox7.Text = temp(0) & &quot;    &quot; & temp(1)
  •                      Me.TextBox7.Visible = True
  •                      jt = &quot;一等奖            &quot; & TextBox7.Text & vbCrLf & jt
  •                      Sleep 80
  •                      Me.TextBox1.Text = &quot;&quot;
  •                      Me.TextBox3.Text = &quot;&quot;
  •                 Case 4
  •                      Me.TextBox8.Text = temp(0)
  •                      Me.TextBox8.Visible = True
  •                      jt = &quot;特等奖               &quot; & TextBox8.Text & vbCrLf & jt
  •                      Sleep 80
  •                      Me.TextBox2.Text = &quot;&quot;
  •                 Case 5
  •                      Me.Shapes(&quot;TextBox 14&quot;).TextFrame.TextRange.Text = &quot;生产线员工奖&quot;
  •                      Me.Shapes(&quot;TextBox 14&quot;).Visible = True
  •                      TextBox5.Text = temp
  •                      jt = jt & vbCrLf & vbCrLf & &quot;生产线员工奖         &quot; & temp
  •                      Sleep 80
  •                      Me.TextBox2.Text = &quot;&quot;
  •                      Me.TextBox4.Text = &quot;办公室员工奖&quot;
  •                 Case 6
  •                      Me.Shapes(&quot;TextBox 15&quot;).TextFrame.TextRange.Text = &quot;办公室员工奖&quot;
  •                      Me.Shapes(&quot;TextBox 15&quot;).Visible = True
  •                      TextBox6.Text = temp
  •                      jt = jt & vbCrLf & &quot;办公室员工奖         &quot; & temp
  •                      Sleep 80
  •                      Me.TextBox2.Text = &quot;&quot;
  •                      Me.TextBox4.Text = &quot;老员工奖&quot;
  •                  Case 7
  •                      Me.Shapes(&quot;TextBox 16&quot;).TextFrame.TextRange.Text = &quot;老员工奖&quot;
  •                      Me.Shapes(&quot;TextBox 16&quot;).Visible = True
  •                      TextBox7.Text = temp
  •                      jt = jt & vbCrLf & &quot;老员工奖             &quot; & temp
  •                      Sleep 80
  •                      Me.TextBox2.Text = &quot;&quot;
  •                      Me.TextBox4.Text = &quot;新员工奖&quot;
  •                  Case 8
  •                      Me.Shapes(&quot;TextBox 17&quot;).TextFrame.TextRange.Text = &quot;新员工奖&quot;
  •                      Me.Shapes(&quot;TextBox 17&quot;).Visible = True
  •                      Me.TextBox8.Text = temp
  •                      jt = jt & vbCrLf & &quot;新员工奖             &quot; & temp
  •                      Sleep 100
  •                      Me.TextBox2.Text = &quot;&quot;
  •          End Select
  •          j = j + 1
  •          Select Case j
  •                 Case 5
  •                      MsgBox &quot;按“确定”按钮,开始抽取特别奖!&quot;
  •                      Me.Shapes(&quot;副标题 2&quot;).TextFrame.TextRange.Text = &quot;附加特别奖&quot;
  •                      Me.TextBox5.Text = &quot;&quot;: Me.TextBox6.Text = &quot;&quot;: Me.TextBox7.Text = &quot;&quot;: Me.TextBox8.Text = &quot;&quot;
  •                      Me.Shapes(&quot;TextBox 14&quot;).Visible = False: Me.Shapes(&quot;TextBox 15&quot;).Visible = False
  •                      Me.Shapes(&quot;TextBox 16&quot;).Visible = False: Me.Shapes(&quot;TextBox 17&quot;).Visible = False
  •                      TextBox4.Text = &quot;生产线员工奖&quot;
  •                      Set s = Nothing                '集合s抽取特别奖时不需
  •                 Case 9                              '抽奖结束
  •                      SlideShowWindows(1).View.Next
  •                      Slide7.Shapes(&quot;Text Box 6&quot;).TextFrame.TextRange.Text = jt
  •                      j = 0
  •                      Me.Shapes(&quot;副标题 2&quot;).TextFrame.TextRange.Text = &quot;幸运大抽奖活动&quot;
  •                      Me.TextBox4.Text = &quot;&quot;: Me.TextBox5.Text = &quot;&quot;: Me.TextBox6.Text = &quot;&quot;: Me.TextBox7.Text = &quot;&quot;: Me.TextBox8.Text = &quot;&quot;
  •                      Me.Shapes(&quot;TextBox 14&quot;).Visible = False: Me.Shapes(&quot;TextBox 15&quot;).Visible = False
  •                      Me.Shapes(&quot;TextBox 16&quot;).Visible = False: Me.Shapes(&quot;TextBox 17&quot;).Visible = False
  •                      ScreenUpdating = True
  •                      Exit Sub
  •                 Case 2 To 4
  •                      For i = 0 To n - 1
  •                          s.Remove (temp(i))         '滤除已抽取号码
  •                      Next
  •                      Me.TextBox4.Text = Mid(&quot;三二一特&quot;, j, 1) & &quot;等奖&quot; '显示待抽的下一奖等
  •          End Select
  •          Exit Do                                    '退出快闪循环准备下一轮抽奖
  •       Else
  •          If n Then
  •             temp = choose(s.Count, n)                's.count意味着已扣减抽取的样本
  •             For i = 0 To n - 1                       '由于temp抽取的序号并未排序,s.remove时可能会造成s(--temp(i))中当时序标--temp(i)的变动和丢失,故在remove之前存好s(--temp(i)),而非存序号
  •                 temp(i) = s(--temp(i)) & &quot;&quot;          'choose作为字典的key已置为文本
  •             Next
  •             Select Case n                            '下框的抽奖区即时显示具体抽中号码
  •                    Case 3
  •                         Me.TextBox1.Visible = True      '因上次抽特等奖时将其隐藏
  •                         Me.TextBox3.Visible = True
  •                         Me.TextBox1.Text = temp(0): Me.TextBox2.Text = temp(1): Me.TextBox3.Text = temp(2)
  •                    Case 2
  •                         Me.TextBox1.Text = temp(0): Me.TextBox3.Text = temp(1)
  •                         Me.TextBox2.Visible = False
  •                    Case 1
  •                         Me.TextBox1.Visible = False: Me.TextBox2.Visible = True: Me.TextBox3.Visible = False
  •                         Me.TextBox2.Text = temp(0)
  •             End Select
  •          Else
  •             Randomize
  •             Select Case j                            '下框的抽奖区即时显示特别奖具体抽中号码
  •                    Case 5
  •                         temp = prr(1, Int(Rnd * UBound(prr, 2)) + 1)
  •                         Me.TextBox2.Text = temp
  •                    Case 6
  •                         temp = frr(1, Int(Rnd * UBound(frr, 2)) + 1)
  •                         Me.TextBox2.Text = temp
  •                    Case 7
  •                         temp = orr(1, Int(Rnd * UBound(orr, 2)) + 1)
  •                         Me.TextBox2.Text = temp
  •                    Case 8
  •                         temp = nrr(1, Int(Rnd * UBound(nrr, 2)) + 1)
  •                         Me.TextBox2.Text = temp
  •             End Select
  •          End If
  •       End If
  •       Sleep 30
  •       DoEvents
  •    Loop
  • End If
  • End Sub
  • Function choose(m%, n%)             'm选n;传回数组的函数不能声明为String,必须为vaiant
  • Dim i%, dt
  • Set dt = CreateObject(&quot;Scripting.Dictionary&quot;)
  • Randomize
  • Do
  •    i = Int(Rnd * (m - 1)) + 1
  •    dt(i & &quot;&quot;) = &quot;&quot;                  '用字典的key来确保不重复抽取
  • Loop Until dt.Count = n
  • choose = dt.keys
  • End Function

复制代码
PPT学习论坛
回复 支持 反对

使用道具 举报

3

主题

10

帖子

69

幻币

江湖少侠

Rank: 2

积分
197
QQ
2017-2-6 20:25:34 显示全部楼层
孜孜以求,不断完美,中见巅峰大作。再用更新,收入囊中,以备后用。谢谢了。
PPT学习论坛
回复 支持 反对

使用道具 举报

4

主题

9

帖子

37

幻币

江湖少侠

Rank: 2

积分
145
QQ
2017-2-6 20:37:15 显示全部楼层
少了与之连用的“限制性抽奖设置-h.xls“文件,测试无法进行。
PPT学习论坛
回复 支持 反对

使用道具 举报

2

主题

6

帖子

68

幻币

一流武者

Rank: 3Rank: 3

积分
309
QQ
2017-2-6 20:42:23 显示全部楼层
是我疏漏!
限制性抽奖设置-h.rar (14.33 KB, 下载次数: 181)
PPT学习论坛
回复 支持 反对

使用道具 举报

3

主题

10

帖子

99

幻币

一流武者

Rank: 3Rank: 3

积分
290
QQ
2017-2-6 20:57:41 显示全部楼层
测试可以,只是刷新较慢,有撤屏卡顿之感,若完善一下更好
PPT学习论坛
回复 支持 反对

使用道具 举报

0

主题

1

帖子

2

幻币

初入江湖

Rank: 1

积分
6
2017-7-7 16:33:28 显示全部楼层
感谢分享。
PPT学习论坛
回复

使用道具 举报

0

主题

41

帖子

3

幻币

江湖少侠

Rank: 2

积分
93
2017-9-19 09:36:38 显示全部楼层
学习了,不错
PPT学习论坛
回复 支持 反对

使用道具 举报

0

主题

49

帖子

3

幻币

江湖少侠

Rank: 2

积分
109
2019-1-9 09:14:15 显示全部楼层
这个好这个真好
PPT学习论坛
回复 支持 反对

使用道具 举报

0

主题

3

帖子

0

幻币

初入江湖

Rank: 1

积分
12
2019-1-9 22:39:13 显示全部楼层
学习学习高手
PPT学习论坛
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册