- 新建一個(gè)PPT
- 設(shè)計(jì)好背景界面
- 點(diǎn)擊菜單視圖-工具欄-Visual Basic
- 點(diǎn)擊圖示,拖動(dòng)按鈕到界面上
- 拖到界面的按鈕上點(diǎn)右鍵,選擇“屬性”
- 在Caption輸入“開始倒計(jì)時(shí)”
- 如下圖所示,再拖動(dòng)幾個(gè)控件到界面上
- 在按鈕上點(diǎn)右鍵,選擇“查看代碼”(或按鍵Alt+F11,打開VBA編程環(huán)境,后雙擊Slide1)
- ff
- 輸入代碼
- Private Declare Function GetTickCount Lib "kernel32.dll" () As Long
- Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)
- 'Private Declare Function PlaySound Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszName As String, ByVal uFlags As Long) As Long
- Const InterVal = 1000 '自定義的時(shí)間間隔
-
- Private Sub CommandButton1_Click()
-
- Static State, myStop As Boolean
- Dim preTime, curTime, myTime, jsTime, txTime As Long
- If State Then myStop = True: Exit Sub
- CommandButton1.Caption = "停止倒計(jì)時(shí)"
- State = True
- preTime = GetTickCount
- myTime = Val(TextBox2) + 1
- jsTime = Val(TextBox2) + 2
- txTime = Val(TextBox3)
- Label3.Visible = False
- Label4.Visible = False
- TextBox2.Visible = False
- TextBox3.Visible = False
- Label2.Caption = "計(jì)時(shí)進(jìn)行中"
- Do
- curTime = GetTickCount
- If curTime - preTime >= InterVal * (jsTime - myTime) Then
- myTime = myTime - 1
- TextBox1 = myTime
- DoEvents
- If myTime = txTime Then
- Label2.Caption = "計(jì)時(shí)將結(jié)束"
- ' Call PlaySound("Ding.wav", 0&)
- End If
- If myTime = 0 Then
- State = False
- myStop = False
- CommandButton1.Caption = "開始倒計(jì)時(shí)"
- ' Call PlaySound("End.wav", 0&)
- Exit Do
- End If
- End If
- Sleep (20)
- Label1 = Time
- DoEvents
- If myStop Then
- State = False
- myStop = False
- CommandButton1.Caption = "開始倒計(jì)時(shí)"
- MsgBox "倒計(jì)時(shí)終止!", vbInformation + vbOKOnly, "操作提示"
- Exit Do
- End If
- Loop
- Label2.Caption = "計(jì)時(shí)時(shí)間到"
- Label3.Visible = True
- Label4.Visible = True
- TextBox2.Visible = True
- TextBox3.Visible = True
- End Sub
- 保存后,按Shift+F5 , 演示。在請(qǐng)輸入倒計(jì)時(shí)時(shí)間(秒)填入60,在倒計(jì)時(shí)結(jié)束前提醒(秒)填入5,點(diǎn)擊“開始倒計(jì)時(shí)”按鈕。
|