谁帮我用VB写一个一小时倒计时,万分感谢
如题,万分感谢 --------------------编程问答--------------------Option Explicit--------------------编程问答-------------------- 我得把时间显示在一个lable上,开始lable上显示开始考试几个字,然后弄一个单击事件,点击开始考试就进入倒计时,我是把宏嵌到PPT上
Dim sum As Long
Dim sum1 As Long
Private Sub Form_Load()
sum1 = 59
sum = 60
Timer1.Interval = 500
End Sub
Private Sub Timer1_Timer()
If lbltime.Caption <> CStr(Time) Then
sum = sum - 1
Text1 = "倒计时" & sum1 & ":" & sum
If sum <= 0 Then
sum = 60
sum1 = sum1 - 1
If sum1 <= 0 Then
MsgBox ("时间到")
Timer1.Enabled = False
End If
End If
End If
End Sub
--------------------编程问答-------------------- 飘过 --------------------编程问答-------------------- 顶。 --------------------编程问答-------------------- http://blog.csdn.net/chenjl1031/archive/2008/01/09/2032579.aspx --------------------编程问答--------------------
Option Explicit--------------------编程问答-------------------- 还是分数有威力啊。 --------------------编程问答-------------------- 貌似ppt没有timer控件
Const Totaltime = 60
Private Sub Command1_Click()
Timer1.Enabled = True
End Sub
Private Sub Form_Load()
Timer1.Interval = 500
Timer1.Enabled = False
Label1.Caption = ""
End Sub
Private Sub Timer1_Timer()
Static i As Integer
Dim sum As Long
Label1.Caption = "考试时间还剩" & Totaltime - i \ 120 & "分钟"
i = i + 1
If Totaltime - i \ 120 <= 0 Then
MsgBox ("时间到")
Timer1.Enabled = False
End If
End Sub
应该这样写
Private Declare Sub Sleep Lib "kernel32.dll" (ByVal dwMilliseconds As Long)--------------------编程问答-------------------- Private Sub CommandButton1_Click()
Private State As Boolean
Private Sub Label1_Click()
Dim preT As Date, curT As Long
If State Then
State = False
Exit Sub
End If
State = True
preT = DateAdd("h", 1, Time)
Do
curT = DateDiff("s", Time, preT)
Label1.Caption = Format((curT \ 3600 & ":" & (curT Mod 3600) \ 60 & ":" & (curT Mod 3600) Mod 60), "HH:MM:SS")
DoEvents
Sleep (500)
DoEvents
If Val(curT) < 0 Or Not State Then
Label1.Caption = "stop" '开始考试
Exit Sub
End If
Loop
End Sub
Dim PauseTime, Start, Finish, TotalTime
Dim t As Integer
Dim a As Integer
If (MsgBox("点击开始考试", 4)) = vbYes Then
PauseTime = 3600 ' 设置暂停时间。
Start = Timer ' 设置开始暂停的时刻。
CommandButton1.Caption = "考试已经开始了0分钟"
MsgBox "ok"
a = 0
Do While Timer < Start + PauseTime
' 将控制让给其他程序。
Finish = Timer ' 设置结束时刻。
TotalTime = Finish - Start ' 计算总时间。
t = TotalTime / 60
If a < t Then
a = t
CommandButton1.Caption = "考试时间已经过去了" + Str(a) + "分钟"
MsgBox a
End If
Loop
Else
End
End If
这个代码没问题,但好像在PPT里MsgBox函数不行,点击开始考试没反应 --------------------编程问答-------------------- PPT里可以用MsgBox函数,不能使用timer --------------------编程问答-------------------- 8楼代码在ppt里测试通过 --------------------编程问答-------------------- 够热闹,走了~~~~~~~` --------------------编程问答-------------------- 路过 --------------------编程问答--------------------
补充:VB , VBA