vb 计时器

来源:百度知道 编辑:UC知道 时间:2024/05/25 09:37:12
一个简易的用timer 控件做的计时器
但是不知道哪里出错了,不能运行阿,请高手帮忙!

代码如下:

Private Sub Command1_Click()
If Command1.Caption = "开始计时" Then Form1.Tag = Timer
If Command1.Caption = "暂停" Then
Command1.Caption = "继续": Timer1.Enabled = False
Else
Command1.Caption = "暂停": Timer1.Enabled = True
End If
End Sub

Private Sub Command2_Click()
Label1.Caption = "00:00:00"
Command1.Enabled = True
Command1.Caption = "开始计时"
Timer1.Enabled = False
End Sub

Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 100
End Sub

Private Sub Timer1_Timer()
Dim m As Long, m1 As Long, t0 As Long, t1 As String, t2 As String
m = Timer - Form1.Tag
t0 = (m * 10) Mod 10
m1 = Int(m)
t1 = Format(m Mod 60, "00:")
t2 = Format((m / 60) Mod 60, "00:")
End Sub
怎么改啊?能不能说的详细点?

'''你这个代码获取时间的部分有点小问题,我帮你改掉了,你复制下面的全部代码再试~~

Private Declare Sub GetSystemTime Lib "kernel32" (lpSystemTime As SYSTEMTIME)

Private Type SYSTEMTIME
wYear As Integer
wMonth As Integer
wDayOfWeek As Integer
wDay As Integer
wHour As Integer
wMinute As Integer
wSecond As Integer
wMilliseconds As Integer
End Type

Private Sub Command1_Click()
If Command1.Caption = "开始计时" Then Form1.Tag = Timer
If Command1.Caption = "暂停" Then
Command1.Caption = "继续": Timer1.Enabled = False
Else
Command1.Caption = "暂停": Timer1.Enabled = True:
End If
End Sub

Private Sub Command2_Click()
Label1.Caption = "00:00:00"
Command1.Enabled = True
Command1.Caption = "开始计时"
Timer1.Enabled = False
End Sub

Private Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval