(39)[转载]ppt的定时器功能_徐自远_新浪博客

office应用 徐 自远 514℃

徐自远的博客


[转载]ppt的定时器功能_徐自远_新浪博客


一、这是一个答题系统。

二、每页上的题限定一个时间,当时间到时自动回到第一页,如果时间未到答完之后进到下一页,此时本页的定时器功能取消,进入下一页的重新定时。

三、每页显示倒计时的时间。

解决方案:

给此文档加一个模块,写入:

Option Explicit
‘声明api函数
Declare Function SetTimer Lib “user32” _
                           (ByVal hwnd As Long, _
                            ByVal nIDEvent As Long, _
                            ByVal uElapse As Long, _
                            ByVal lpTimerFunc As Long) As Long

Declare Function KillTimer Lib “user32” _
                           (ByVal hwnd As Long, _
                            ByVal nIDEvent As Long) As Long
Public SecondCtr As Integer
Public TimerID As Long
Public bTimerState As Boolean
Public counts As Integer
Public myTextBox As TextBox
Public isStart As Boolean


‘开始计时
Sub TimerStart(ByVal time As Integer, ByRef control_textBox As TextBox)
‘传递一共多少秒, 把一个文本框引用过来,用于显示倒计时的时间。
   counts = time / 1000
   Set myTextBox = control_textBox
   TimerID = SetTimer(0, 0, 1000, AddressOf TimerProc)
   isStart = True

End Sub

‘停止计时
Sub timerStop()
   If isStart = False Then
       Exit Sub
   End If
  
   TimerID = KillTimer(0, TimerID)
   isStart = False
End Sub
Sub TimerProc(ByVal hwnd As Long, _
                   ByVal uMsg As Long, _
                   ByVal idEvent As Long, _
                   ByVal dwTime As Long)
       counts = counts – 1
       Dim tmp
       tmp = “倒计时” & counts & “秒”
       myTextBox.Text = tmp
      
       If (counts <= 0) Then
           TimerID = KillTimer(0, TimerID)
           ActivePresentation.SlideShowWindow.View.GotoSlide 1
       End If

        ‘跳转到第几页
     
      
End Sub

之后在第一张或第二张幻灯片上写上如下代码:

Sub OnSlideShowPageChange()

Dim time As Integer
time = 5000  ‘每页时间为5秒
timerStop  ‘清理定时器

‘初始化每个页面上的文本框
Slide2.TextBox1.Text = “…”
Slide3.TextBox1.Text = “…”
Slide4.TextBox1.Text = “…”
Slide5.TextBox1.Text = “…”
Slide6.TextBox1.Text = “…”
‘如果当前的页面为第一页则….   
If ActivePresentation.SlideShowWindow.View.CurrentShowPosition = 1 Then
   MsgBox “欢迎来到答题系统,注意每页题为5秒。”

‘如果为第二页….
ElseIf ActivePresentation.SlideShowWindow.View.CurrentShowPosition = 2 Then  
   timerStop ‘先清理上一次的计时器。
   Slide2.TextBox1.Text = “倒计时:” & time / 1000 & “秒”
   TimerStart time, Slide2.TextBox1  ‘这个位置timerStart是定时开始,time为5秒的时间,Slide2.TextBox1为第二页的文本框。
  
ElseIf ActivePresentation.SlideShowWindow.View.CurrentShowPosition = 3 Then
   timerStop
   Slide2.TextBox1.Text = “倒计时:” & time / 1000 & “秒”
   TimerStart time, Slide3.TextBox1
ElseIf ActivePresentation.SlideShowWindow.View.CurrentShowPosition = 4 Then
  timerStop
   Slide2.TextBox1.Text = “倒计时:” & time / 1000 & “秒”
   TimerStart time, Slide4.TextBox1
ElseIf ActivePresentation.SlideShowWindow.View.CurrentShowPosition = 5 Then
   timerStop
   Slide2.TextBox1.Text = “倒计时:” & time / 1000 & “秒”
   TimerStart time, Slide5.TextBox1
ElseIf ActivePresentation.SlideShowWindow.View.CurrentShowPosition = 6 Then
  timerStop
   Slide2.TextBox1.Text = “倒计时:” & time / 1000 & “秒”
   TimerStart time, Slide6.TextBox1
End If

End Sub

以上就实现了简单的定时效果。

转载请注明:徐自远的乱七八糟小站 » (39)[转载]ppt的定时器功能_徐自远_新浪博客

喜欢 (0)

苏ICP备18041234号-1 bei_an 苏公网安备 32021402001397号