private sub form1_onload() timer1.enable=false end sub private sub timer1_timer() me.caption=time() end sub private sub command1_click() timer1.enable=true end sub
用Timer函数 ------------Dim stTimePrivate Sub Command1_Click() stTime = Timer End SubPrivate Sub Command2_Click() MsgBox Timer - stTime End Sub
Option Explicit Dim i As Long Private Sub Form_Load() Me.Show Me.Timer1.Interval = 1000 Me.Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer() i = i + 1 Me.Label1.Caption = "耗时" + CStr(i) + "秒" End Sub
在窗体中添加一command 和label 控件 Option Explicit Public ftime, stime, mtime, ttime, ftime2, stime2, mtime2, ttime2Private Sub Form_Load() ttime = Time '判断晚上12点 If Left(ttime, 1) = 0 Then ftime = Mid(ttime, 3, 2) Else stime = Left(ttime, 2) ftime = Mid(ttime, 4, 2) End If mtime = Right(ttime, 2) End SubPrivate Sub Command1_Click() Dim m, f, s, ff, ss As Long ttime2 = Time '判断晚上12点 If Left(ttime2, 1) = 0 Then ftime2 = CLng(Mid(ttime2, 3, 2)) Else stime2 = CLng(Left(ttime2, 2)) ftime2 = CLng(Mid(ttime2, 4, 2)) End If mtime2 = CLng(Right(ttime2, 2)) m = Val(mtime2) - Val(mtime) f = Val(ftime2 - ftime) s = Val(stime2 - stime) '判断秒 If m < 0 Then m = 60 - Abs(m) ff = Val(f - 1) Else m = mtime2 - mtime ff = Val(ftime2 - ftime) End If '判断分 Select Case ff Case ff = 0 ff = Val(ftime2 - 1 - ftime) Case ff > 0 ss = Val(stime2 - stime) Case ff < 0 ff = 60 - Abs(f) ss = Val(s - 1) End Select Select Case ss Case ss = 0 ss = Val(stime2 - 1 - stime) Case ss > 0 ss = Val(stime2 - stime) Case ss < 0 ss = 24 - Abs(s) End Select
Label1.Caption = ss & "时" & ff & "分" & m & "秒" End Sub
timer1.enable=false
end sub
private sub timer1_timer()
me.caption=time()
end sub
private sub command1_click()
timer1.enable=true
end sub
------------Dim stTimePrivate Sub Command1_Click()
stTime = Timer
End SubPrivate Sub Command2_Click()
MsgBox Timer - stTime
End Sub
Dim i As Long
Private Sub Form_Load()
Me.Show
Me.Timer1.Interval = 1000
Me.Timer1.Enabled = True
End SubPrivate Sub Timer1_Timer()
i = i + 1
Me.Label1.Caption = "耗时" + CStr(i) + "秒"
End Sub
Option Explicit
Public ftime, stime, mtime, ttime, ftime2, stime2, mtime2, ttime2Private Sub Form_Load()
ttime = Time
'判断晚上12点
If Left(ttime, 1) = 0 Then
ftime = Mid(ttime, 3, 2)
Else
stime = Left(ttime, 2)
ftime = Mid(ttime, 4, 2)
End If
mtime = Right(ttime, 2)
End SubPrivate Sub Command1_Click()
Dim m, f, s, ff, ss As Long
ttime2 = Time
'判断晚上12点
If Left(ttime2, 1) = 0 Then
ftime2 = CLng(Mid(ttime2, 3, 2))
Else
stime2 = CLng(Left(ttime2, 2))
ftime2 = CLng(Mid(ttime2, 4, 2))
End If
mtime2 = CLng(Right(ttime2, 2))
m = Val(mtime2) - Val(mtime)
f = Val(ftime2 - ftime)
s = Val(stime2 - stime)
'判断秒
If m < 0 Then
m = 60 - Abs(m)
ff = Val(f - 1)
Else
m = mtime2 - mtime
ff = Val(ftime2 - ftime)
End If
'判断分
Select Case ff
Case ff = 0
ff = Val(ftime2 - 1 - ftime)
Case ff > 0
ss = Val(stime2 - stime)
Case ff < 0
ff = 60 - Abs(f)
ss = Val(s - 1)
End Select
Select Case ss
Case ss = 0
ss = Val(stime2 - 1 - stime)
Case ss > 0
ss = Val(stime2 - stime)
Case ss < 0
ss = 24 - Abs(s)
End Select
Label1.Caption = ss & "时" & ff & "分" & m & "秒"
End Sub