用VB设计一个秒表程序
运行时单击“开始”按钮,秒表开始计时;单击“停止”按钮,停止计时;单击“清空”按钮,秒表清零。要求计时精度达到0.01秒。...
运行时单击“开始”按钮,秒表开始计时;单击“停止”按钮,停止计时;单击“清空”按钮,秒表清零。要求计时精度达到0.01秒。
展开
2个回答
推荐于2017-05-26
展开全部
Option Explicit
Dim MinSec As Integer
Dim Sec As Integer
Dim Minute As Integer
Dim Hour As Integer
Private Sub Command1_Click() '开始按钮
Timer1.Enabled = True
End SubPrivate Sub Command2_Click() '停止
Timer1.Enabled = False
End SubPrivate Sub Command3_Click() '清除
Timer1.Enabled = False
Hour = 0
Minute = 0
MinSec = 0
Sec = 0
Label1.Caption = Format(Hour, "00") & "时" & Format(Minute, "00") & "分" & Format(Sec, "00") & "秒" & Format(MinSec, "00")
End SubPrivate Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 10
Form1.Caption = "秒表"
Command1.Caption = "开始"
Command2.Caption = "停止"
Command3.Caption = "清除"
End SubPrivate Sub Timer1_Timer()
MinSec = MinSec + 1
If MinSec = 100 Then
MinSec = 0
Sec = Sec + 1
If Sec = 60 Then
Sec = 0
Minute = Minute + 1
If Minute = 60 Then
Minute = 0
Hour = Hour + 1
Else
End If
Else
End If
Else
End If
Label1.Caption = Format(Hour, "00") & "时" & Format(Minute, "00") & "分" & Format(Sec, "00") & "秒" & Format(MinSec, "00")
End Sub
Dim MinSec As Integer
Dim Sec As Integer
Dim Minute As Integer
Dim Hour As Integer
Private Sub Command1_Click() '开始按钮
Timer1.Enabled = True
End SubPrivate Sub Command2_Click() '停止
Timer1.Enabled = False
End SubPrivate Sub Command3_Click() '清除
Timer1.Enabled = False
Hour = 0
Minute = 0
MinSec = 0
Sec = 0
Label1.Caption = Format(Hour, "00") & "时" & Format(Minute, "00") & "分" & Format(Sec, "00") & "秒" & Format(MinSec, "00")
End SubPrivate Sub Form_Load()
Timer1.Enabled = False
Timer1.Interval = 10
Form1.Caption = "秒表"
Command1.Caption = "开始"
Command2.Caption = "停止"
Command3.Caption = "清除"
End SubPrivate Sub Timer1_Timer()
MinSec = MinSec + 1
If MinSec = 100 Then
MinSec = 0
Sec = Sec + 1
If Sec = 60 Then
Sec = 0
Minute = Minute + 1
If Minute = 60 Then
Minute = 0
Hour = Hour + 1
Else
End If
Else
End If
Else
End If
Label1.Caption = Format(Hour, "00") & "时" & Format(Minute, "00") & "分" & Format(Sec, "00") & "秒" & Format(MinSec, "00")
End Sub
深圳云诺科技
2024-11-11 广告
2024-11-11 广告
甘特图工具是一种直观展示项目时间与进度管理的有效手段。在深圳云诺互联科技有限公司,我们常利用甘特图来规划项目阶段、任务分配及预计完成时间。通过清晰的时间轴和任务条,团队成员能迅速了解项目全局,把握关键节点。甘特图还具备任务依赖关系设置、进度...
点击进入详情页
本回答由深圳云诺科技提供
2013-09-23
展开全部
我写了个 显示是用的标签 开始和停止是用的一个按纽 还有一个时钟 一个清除的 代码:Option ExplicitPrivate Sub Command1_Click()
If Command1.Caption = "开始" Then
Dim StartTimer!, GTimer!, GDay%
Command1.Caption = "停止"
StartTimer = Timer
10 DoEvents
If GTimer <= -0.001 Then GDay = GDay + 1 '此处之所以不用<0而用<=0.001,就是为了防止出现刚点击就多了24小时的现象。
GTimer = Timer + 86400 * GDay - StartTimer
Label1.Caption = Format(Int(GTimer / 3600), "00") & ":" & Format(Int((GTimer Mod 3600) / 60), "00") & ":" & Format(Int(GTimer Mod 60), "00") & ":" & Format(Int((GTimer - Int(GTimer)) * 1000), "000")
If Command1.Caption = "停止" Then GoTo 10
Else
Command1.Caption = "开始"
End If
End SubPrivate Sub Command2_Click()
Label1.Caption = "00.00.00"
End SubPrivate Sub Form_Load()
Command1.Caption = "开始"
End Sub
If Command1.Caption = "开始" Then
Dim StartTimer!, GTimer!, GDay%
Command1.Caption = "停止"
StartTimer = Timer
10 DoEvents
If GTimer <= -0.001 Then GDay = GDay + 1 '此处之所以不用<0而用<=0.001,就是为了防止出现刚点击就多了24小时的现象。
GTimer = Timer + 86400 * GDay - StartTimer
Label1.Caption = Format(Int(GTimer / 3600), "00") & ":" & Format(Int((GTimer Mod 3600) / 60), "00") & ":" & Format(Int(GTimer Mod 60), "00") & ":" & Format(Int((GTimer - Int(GTimer)) * 1000), "000")
If Command1.Caption = "停止" Then GoTo 10
Else
Command1.Caption = "开始"
End If
End SubPrivate Sub Command2_Click()
Label1.Caption = "00.00.00"
End SubPrivate Sub Form_Load()
Command1.Caption = "开始"
End Sub
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询