Public MyDisplayTime As DatePrivate Sub Command1_Click() If Not StartCount Then Command1.Caption = "开始计时" Else Command1.Caption = "停止计时" End If StartCount End SubPrivate Sub Form_Load() MyDisplayTime = Time Label1.Caption = MyDisplayTimeEnd SubStatic Function StartCount() As Boolean If Not StartCount Then Timer1.Interval = 1000 StartCount = True Else Timer1.Interval = 0 StartCount = False End If End FunctionPrivate Sub Timer1_Timer() Dim MyDisplaySec Dim MyDisplayMin Dim MyDisplayHourMyDisplaySec = Format(MyDisplayTime, "S") - 1 MyDisplayMin = Format(MyDisplayTime, "N") MyDisplayHour = Format(MyDisplayTime, "h") Debug.Assert MyDisplaySec <> 0 If MyDisplaySec = 0 Then MyDisplaySec = 59 MyDisplayMin = Format(MyDisplayTime, "N") - 1 Else If MyDisplayMin = 0 Then MyDisplayMin = 59 MyDisplayHour = Format(MyDisplayTime, "h") - 1 End If End If MyDisplayTime = MyDisplayHour & ":" & MyDisplayMin & ":" & MyDisplaySec Label1.Caption = MyDisplayTime End Sub
'该例子假定总时间为8000秒,当然可以写改为别的值,例如一首歌曲的长度,将时间 '先转换为秒制 Dim x As Long '总时间 Dim z As Long '剩余时间 Dim h As Long '小时 Dim hy As Long '小时余数 Dim m As Long '分钟 Dim my As Long ' 分钟余数 Dim s As Long '秒数
Private Sub Form_Initialize() Label4.Visible = False Label5.Visible = False x = 8000 Timer1.Enabled = True Timer1.Interval = 1000 '一秒钟触发一次 Form1.AutoRedraw = True End SubPrivate Sub Timer1_Timer() Label4.Visible = True Label5.Visible = True Static y As Long '将其定义为静态变量 z = x - y h = z \ 3600 '小时 hy = z Mod 3600 'yu m = hy \ 60 '分 my = hy Mod 60 'yu2 s = my Mod 60 '秒Label1.Caption = CStr(h) Label2.Caption = CStr(m) Label3.Caption = CStr(s) Form1.AutoRedraw = Trueif h=0 and m=0 and s =0 then timer1.enable=false end if y = y + 1 End Sub'你自己在想象一下,可以做出像winmp一样的效果 有别的问题可以与我联系[email protected]
注意:label14,label5 caption 为":"
需要这么多LABEL吗?我好象只有一个,就是数字显示用的一个LABEL。
Dim BeginTime As Date Private Sub Form_Load() BeginTime = Time Label1 = BeginTime Timer1.Interval = 500 End SubPrivate Sub Timer1_Timer() Label1 = BeginTime - (Time - BeginTime) End Sub
If Not StartCount Then
Command1.Caption = "开始计时"
Else
Command1.Caption = "停止计时"
End If
StartCount
End SubPrivate Sub Form_Load()
MyDisplayTime = Time
Label1.Caption = MyDisplayTimeEnd SubStatic Function StartCount() As Boolean
If Not StartCount Then
Timer1.Interval = 1000
StartCount = True
Else
Timer1.Interval = 0
StartCount = False
End If
End FunctionPrivate Sub Timer1_Timer()
Dim MyDisplaySec
Dim MyDisplayMin
Dim MyDisplayHourMyDisplaySec = Format(MyDisplayTime, "S") - 1
MyDisplayMin = Format(MyDisplayTime, "N")
MyDisplayHour = Format(MyDisplayTime, "h")
Debug.Assert MyDisplaySec <> 0
If MyDisplaySec = 0 Then
MyDisplaySec = 59
MyDisplayMin = Format(MyDisplayTime, "N") - 1
Else
If MyDisplayMin = 0 Then
MyDisplayMin = 59
MyDisplayHour = Format(MyDisplayTime, "h") - 1
End If
End If
MyDisplayTime = MyDisplayHour & ":" & MyDisplayMin & ":" & MyDisplaySec
Label1.Caption = MyDisplayTime
End Sub
'先转换为秒制
Dim x As Long '总时间
Dim z As Long '剩余时间
Dim h As Long '小时
Dim hy As Long '小时余数
Dim m As Long '分钟
Dim my As Long ' 分钟余数
Dim s As Long '秒数
Private Sub Form_Initialize()
Label4.Visible = False
Label5.Visible = False
x = 8000
Timer1.Enabled = True
Timer1.Interval = 1000 '一秒钟触发一次
Form1.AutoRedraw = True
End SubPrivate Sub Timer1_Timer()
Label4.Visible = True
Label5.Visible = True
Static y As Long '将其定义为静态变量
z = x - y
h = z \ 3600 '小时
hy = z Mod 3600 'yu
m = hy \ 60 '分
my = hy Mod 60 'yu2
s = my Mod 60 '秒Label1.Caption = CStr(h)
Label2.Caption = CStr(m)
Label3.Caption = CStr(s)
Form1.AutoRedraw = Trueif h=0 and m=0 and s =0 then
timer1.enable=false
end if
y = y + 1
End Sub'你自己在想象一下,可以做出像winmp一样的效果
有别的问题可以与我联系[email protected]
Private Sub Form_Load()
BeginTime = Time
Label1 = BeginTime
Timer1.Interval = 500
End SubPrivate Sub Timer1_Timer()
Label1 = BeginTime - (Time - BeginTime)
End Sub