vb计时器的设计
设计一个计时器,一个text,两个command按钮,单击”开始计时“按钮,计时器按”时:分:秒“的形式开始计时,并显示在文本框中,此时开始计时,按钮变成”停止计时“按钮...
设计一个计时器,一个text,两个command按钮,单击”开始计时“按钮,计时器按”时:分:秒“的形式开始计时,并显示在文本框中,此时开始计时,按钮变成”停止计时“按钮,停止计时,单击”清零”按钮,清除文本框内的时间。请问这个程序该怎么设计
展开
1个回答
展开全部
新建一个文本框,两个按钮,一个时间控件
然后打开代码框 把里面的代码全清空,再把下面的复制进去就可以了
Dim a, b, c, d As Integer
Private Sub Command1_Click()
If Command1.Caption = "开始计时" Then
Timer1.Enabled = True
Timer1.Interval = 100
Command1.Caption = "停止计时"
Else
Timer1.Enabled = False
Timer1.Interval = 0
Command1.Caption = "开始计时"
End If
End Sub
Private Sub Command2_Click()
a = 0
b = 0
c = 0
d = 0
Text1.Text = a & ":" & b & ":" & c & ":" & d
Timer1.Enabled = False
Timer1.Interval = 0
End Sub
Private Sub Form_Load()
a = 0
b = 0
c = 0
d = 0
Text1.Text = a & ":" & b & ":" & c & ":" & d
Command1.Caption = "开始计时"
Command2.Caption = "清零"
Timer1.Enabled = False
Timer1.Interval = 0
End Sub
Private Sub Timer1_Timer()
d = d + 1
If d = 9 Then c = c + 1: d = 0
If c = 59 Then c = 0: b = b + 1
If b = 59 Then b = 0: a = a + 1
Text1.Text = a & ":" & b & ":" & c & ":" & d
End Sub
然后打开代码框 把里面的代码全清空,再把下面的复制进去就可以了
Dim a, b, c, d As Integer
Private Sub Command1_Click()
If Command1.Caption = "开始计时" Then
Timer1.Enabled = True
Timer1.Interval = 100
Command1.Caption = "停止计时"
Else
Timer1.Enabled = False
Timer1.Interval = 0
Command1.Caption = "开始计时"
End If
End Sub
Private Sub Command2_Click()
a = 0
b = 0
c = 0
d = 0
Text1.Text = a & ":" & b & ":" & c & ":" & d
Timer1.Enabled = False
Timer1.Interval = 0
End Sub
Private Sub Form_Load()
a = 0
b = 0
c = 0
d = 0
Text1.Text = a & ":" & b & ":" & c & ":" & d
Command1.Caption = "开始计时"
Command2.Caption = "清零"
Timer1.Enabled = False
Timer1.Interval = 0
End Sub
Private Sub Timer1_Timer()
d = d + 1
If d = 9 Then c = c + 1: d = 0
If c = 59 Then c = 0: b = b + 1
If b = 59 Then b = 0: a = a + 1
Text1.Text = a & ":" & b & ":" & c & ":" & d
End Sub
AiPPT
2024-09-19 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询