用VB编写一个计时器,怎么编?
在一个form窗体上画了一个文本框,两个命令按钮。一个命令按钮为开始,单击开始后,文本框内开始计时,格式为(00:00:00.0)。然后开始按钮的caption变为暂停。...
在一个form窗体上画了一个文本框,两个命令按钮。一个命令按钮为开始,单击开始后,文本框内开始计时,格式为(00:00:00.0)。然后开始按钮的caption变为暂停。另一个命令按钮为重置,单击重置后文本框内的计时重置为(00:00:00.0)!
展开
3个回答
展开全部
private sub cmd1_click()
if cmd1.caption="开始" then
text1=format(now-now,"hh:mm:ss")
timer1.enabled=ture
cmd1.caption="暂停"
else
timer1.enabled=false
cmd1.caption="继续"
end sub
private cmd2_click()
text1=format(now-now,"hh:mm:ss")
timer1.enabled=ture
end sub
private timer1_timer()
text1=Format(DateAdd("s", 1, cdate(text1)), "hh:mm:ss")
end sub
if cmd1.caption="开始" then
text1=format(now-now,"hh:mm:ss")
timer1.enabled=ture
cmd1.caption="暂停"
else
timer1.enabled=false
cmd1.caption="继续"
end sub
private cmd2_click()
text1=format(now-now,"hh:mm:ss")
timer1.enabled=ture
end sub
private timer1_timer()
text1=Format(DateAdd("s", 1, cdate(text1)), "hh:mm:ss")
end sub
展开全部
Dim s As Single
Dim m As Integer
Dim h%
Private Sub Command1_Click()
If Command1.Caption = "暂停" Then
Command1.Caption = "继续"
Timer1.Enabled = False
Else
Command1.Caption = "暂停"
Timer1.Enabled = True
End If
End Sub
Private Sub Command2_Click()
s = 0
m = 0
h = 0
Text1.Text = "00:00:00"
End Sub
Private Sub Timer1_Timer()
If s <= 59.9 Then
s = s + 0.1
Else
m = m + 1
s = 0
End If
If m = 60 Then
h = h + 1
m = 0
End If
Text1.Text = Format(h, "00") + ":" + Format(m, "00") + ":" + Format(s, "00.0")
End Sub
Dim m As Integer
Dim h%
Private Sub Command1_Click()
If Command1.Caption = "暂停" Then
Command1.Caption = "继续"
Timer1.Enabled = False
Else
Command1.Caption = "暂停"
Timer1.Enabled = True
End If
End Sub
Private Sub Command2_Click()
s = 0
m = 0
h = 0
Text1.Text = "00:00:00"
End Sub
Private Sub Timer1_Timer()
If s <= 59.9 Then
s = s + 0.1
Else
m = m + 1
s = 0
End If
If m = 60 Then
h = h + 1
m = 0
End If
Text1.Text = Format(h, "00") + ":" + Format(m, "00") + ":" + Format(s, "00.0")
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
Dim X As Integer, SS As Double, HH As Double, MM As Double, JS As Double
Private Sub Command1_Click()
If X = 0 Then
Command1.Caption = "开始"
X = 1
Timer1.Enabled = True
Else
Command1.Caption = "暂停"
Timer1.Enabled = False
X = 0
End If
End Sub
Private Sub Command2_Click()
HH = 0
MM = 0
SS = 0
JS = 0
X = 0
Text1.Text = CStr(HH) & ":" & CStr(MM) & ":" & CStr(SS)
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
Command1.Caption = "开始"
Command2.Caption = "重置"
HH = 0
MM = 0
SS = 0
JS = 0
End Sub
Private Sub Timer1_Timer()
JS = JS + 1
If JS > 0 Then HH = (JS \ (60 * 60)) \ 10
MM = (JS - HH * 60 * 10) \ (10 * 60)
SS = (JS - HH * 60 * 60 * 10 - MM * 60 * 10) / 10
If SS < 1 Then
Text1.Text = CStr(HH) & ":" & CStr(MM) & ":00" & CStr(SS)
ElseIf SS < 10 Then
Text1.Text = CStr(HH) & ":" & CStr(MM) & ":0" & CStr(SS)
Else
Text1.Text = CStr(HH) & ":" & CStr(MM) & ":" & CStr(SS)
End If
End Sub
Private Sub Command1_Click()
If X = 0 Then
Command1.Caption = "开始"
X = 1
Timer1.Enabled = True
Else
Command1.Caption = "暂停"
Timer1.Enabled = False
X = 0
End If
End Sub
Private Sub Command2_Click()
HH = 0
MM = 0
SS = 0
JS = 0
X = 0
Text1.Text = CStr(HH) & ":" & CStr(MM) & ":" & CStr(SS)
End Sub
Private Sub Form_Load()
Timer1.Interval = 100
Timer1.Enabled = True
Command1.Caption = "开始"
Command2.Caption = "重置"
HH = 0
MM = 0
SS = 0
JS = 0
End Sub
Private Sub Timer1_Timer()
JS = JS + 1
If JS > 0 Then HH = (JS \ (60 * 60)) \ 10
MM = (JS - HH * 60 * 10) \ (10 * 60)
SS = (JS - HH * 60 * 60 * 10 - MM * 60 * 10) / 10
If SS < 1 Then
Text1.Text = CStr(HH) & ":" & CStr(MM) & ":00" & CStr(SS)
ElseIf SS < 10 Then
Text1.Text = CStr(HH) & ":" & CStr(MM) & ":0" & CStr(SS)
Else
Text1.Text = CStr(HH) & ":" & CStr(MM) & ":" & CStr(SS)
End If
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询