用vb的timer做一个计时器程序

包括开始、停止、重置,共3个按钮计时单位精确到0.01秒重置后,再按开始是从0开始重新计时的计时中会溢出错误?请高手写一下代码,特别是重置后,我自己做的时候不能重新从0开... 包括开始、停止、重置,共3个按钮
计时单位精确到0.01秒
重置后,再按开始是从0开始重新计时的
计时中会溢出错误?
请高手写一下代码,特别是重置后,我自己做的时候不能重新从0开始计时,而是又接着停止时的时间继续下去!!!
还要在label上显示,刚忘了
展开
 我来答
百度网友bdb9803
2014-07-16 · TA获得超过1.1万个赞
知道大有可为答主
回答量:1.1万
采纳率:53%
帮助的人:9898万
展开全部

窗体上放一个Label,三个Command按钮:

Dim h As Integer, m As Integer, s As Integer, ms As Integer

Private Sub Command1_Click()
Timer1.Enabled = True
Timer1_Timer
End Sub

Private Sub Command2_Click()
Timer1.Enabled = False
End Sub

Private Sub Command3_Click()
h = 0
m = 0
s = 0
ms = 0
Label1.Caption = Format(h, "00") & ":" & Format(m, "00") & _
        ":" & Format(s, "00") & ":" & Format(ms, "000")
End Sub

Private Sub Form_Load()
Command1.Caption = "开始"
Command2.Caption = "停止"
Command3.Caption = "重置"
Label1.Caption = ""
Timer1.Interval = 10
Timer1.Enabled = False
End Sub

Private Sub Timer1_Timer()
ms = ms + 10
If ms > 999 Then s = s + 1: ms = 0
If s > 59 Then m = m + 1: s = 0
If m > 59 Then h = h + 1: m = 0
Label1.Caption = Format(h, "00") & ":" & Format(m, "00") & _
        ":" & Format(s, "00") & ":" & Format(ms, "000")
End Sub

AiPPT
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图... 点击进入详情页
本回答由AiPPT提供
tannotour6
2014-07-16 · 超过13用户采纳过TA的回答
知道答主
回答量:48
采纳率:100%
帮助的人:30.5万
展开全部
Public Class Form1
    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        Label1.Text = Label1.Text + 0.01
    End Sub
    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Timer1.Enabled = True
        Button2.Enabled = True
        Button1.Enabled = False
        Button3.Enabled = False
    End Sub
    Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
        Timer1.Enabled = False
        Button1.Enabled = True
        Button3.Enabled = True
    End Sub
    Private Sub Button3_Click(sender As Object, e As EventArgs) Handles Button3.Click
        Timer1.Enabled = False
        Label1.Text = 0
    End Sub
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Button2.Enabled = False
        Button3.Enabled = False
    End Sub
End Class
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
tmartin1981
2014-07-16 · TA获得超过209个赞
知道小有建树答主
回答量:516
采纳率:0%
帮助的人:334万
展开全部
Option Explicit
--------------------------------------------------
Static iSec As Integer
Static iMin As Integer
Static iHour As Integer

--------------------------------------------------
Private Sub Command1_Click()

Timer1.Enabled = True

End Sub
--------------------------------------------------
Private Sub Command2_Click()

Timer1.Enabled = False

End Sub

Private Sub Command3_Click()

Timer1.Enabled = False
iSec = 0
iMin = 0
iHour = 0

End Sub

--------------------------------------------------
Private Sub Timer1_Timer()

iSec = iSec + 1

If iSec >= 60 Then
iMin = iMin + 1
iSec = 0

If iMin >= 60 Then
iHour = iHour + 1
iMin = 0
End If

End If

Label1.Caption = Format(iHour, "00") & ":" & _
Format(iMin, "00") & ":" & _
Format(iSec, "00")

End Sub
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
易寻桃0k
2014-07-16 · 超过36用户采纳过TA的回答
知道小有建树答主
回答量:81
采纳率:100%
帮助的人:38.9万
展开全部
1、溢出错误是因为你定义的数据类型不够,你定义double类型,保证不会溢出
2、按重置的时候,同时把累积的数清零。
更多追问追答
追问
具体怎么编码呢
追答
留下QQ或邮箱,源代码发给你
本回答被提问者采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
收起 2条折叠回答
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式