用vb的timer做一个计时器程序
包括开始、停止、重置,共3个按钮计时单位精确到0.01秒重置后,再按开始是从0开始重新计时的计时中会溢出错误?请高手写一下代码,特别是重置后,我自己做的时候不能重新从0开...
包括开始、停止、重置,共3个按钮
计时单位精确到0.01秒
重置后,再按开始是从0开始重新计时的
计时中会溢出错误?
请高手写一下代码,特别是重置后,我自己做的时候不能重新从0开始计时,而是又接着停止时的时间继续下去!!!
还要在label上显示,刚忘了 展开
计时单位精确到0.01秒
重置后,再按开始是从0开始重新计时的
计时中会溢出错误?
请高手写一下代码,特别是重置后,我自己做的时候不能重新从0开始计时,而是又接着停止时的时间继续下去!!!
还要在label上显示,刚忘了 展开
展开全部
窗体上放一个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 广告
2024-09-19 广告
随着AI技术的飞速发展,如今市面上涌现了许多实用易操作的AI生成工具1、简介:AiPPT: 这款AI工具智能理解用户输入的主题,提供“AI智能生成”和“导入本地大纲”的选项,生成的PPT内容丰富多样,可自由编辑和添加元素,图表类型包括柱状图...
点击进入详情页
本回答由AiPPT提供
展开全部
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
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
--------------------------------------------------
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
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
1、溢出错误是因为你定义的数据类型不够,你定义double类型,保证不会溢出
2、按重置的时候,同时把累积的数清零。
2、按重置的时候,同时把累积的数清零。
更多追问追答
追问
具体怎么编码呢
追答
留下QQ或邮箱,源代码发给你
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询