运动手表 [英] Sport Watch

查看:125
本文介绍了运动手表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是Timer的新手
那么为什么要制作运动计时器(就像实时运动计时器一样)
我编写了以下代码,但它与真正的计时器不一样:((..请帮助我

这是...

Hi, I am newbie in Timer
So why i want to make Sport Timer(just like real time sport timer)
i wrote the following code but it isn''t same as real timer :(( . Help Me Please

Here it is ...

Private Sub Tmr_Tick(ByVal sender As Object, ByVal e As System.EventArgs)
        Dim tmrDyncsub As System.Windows.Forms.Timer
        tmrDyncsub = CType(sender, System.Windows.Forms.Timer)
        Dim AlltheTime As String
        '' _millisecond += 1
        ms += 1
        If ms = 100 Then
            ms = 0
            sec += 1
        End If
        If sec = 60 Then
            sec = 0
            min += 1
        End If
        AlltheTime = min.ToString() & " : " & sec.ToString() & " : " & ms.ToString()
        tmrElapse(TimerCountClick) = AlltheTime
        ''If _millisecond = 11 Then
        ''    MsgBox("Hola People")
        ''End If
        Me.Text = AlltheTime
        ''If sec = 5 Then
        ''    tmrDyncsub.Stop()
        ''    MsgBox(AlltheTime)
        ''    Me.Text = "123"
        ''End If
    End Sub


如果可能的话请帮我.


if possible Hlep Me.
Please

推荐答案

如果您正在寻找经过的时间,您要做的就是保存秒表启动时的当前日期时间,并将其与当前时间进行比较.是停止,或在触发计时器事件时停止.无需自己维持分钟,秒或毫秒.
If you''re looking for elapsed time all you need to do is save the current datetime when the stopwatch is started and compare it to the current datetime when is is stopped, or when the timer event is triggered. No need to maintain minutes, second or milliseconds on your own.


Mark的意思更像是:

What Mark meant was something more like:

''Store the current time when you start your timer
Dim startTime As DateTime
startTime = DateTime.Now;

''Inside Tmr_Tick you can just check how much time has passed
Dim elapsed As TimeSpan
elapsed = startTime - DateTime.Now;



然后,您可以获取该TimeSpan的小时数,分钟数,秒数和毫秒数.

还值得一提的是,标准Timer的分辨率不是很高(您可能已经注意到).您当前正在尝试将间隔"设置为1,但希望的最佳值接近20ms.

最后一件事,不是添加其他信息来回答您自己的问题,而是应该编辑原始问题,这使其他人可以更轻松地为您提供帮助.



You can then get the number of hours, minutes, seconds and milliseconds fro m that TimeSpan.

It is also worth mentioning that the standard Timer doesn''t have a very high resolution (as you may have noticed). You currently trying to set your Interval to 1 but the best that you can hope for is closer to 20ms.

One last thing, instead of adding an answer to your own question with additional information you should edit your original question, this makes it easier for other people to help you.


马克,我想ms需要增加.你说先保存日期时间,我该怎么办.我尝试仅添加毫秒.请参阅以下代码,但是它不起作用.请问我该怎么办?帮帮我...:((<
hi Mark, I think ms need to increase. u said save datetime first, how do i. I try to Add millisecond only. see the following code but it isn''t work. Pls, how do i do ? Help me... :((

Dim tmr As System.Windows.Forms.Timer
   Dim ts1 As New TimeSpan(0, 0, 0, 0)


Dim ms, sec, min As Integer





Private Sub Ticker_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs)
        Me.Text = ts1.Seconds & ":" & ts1.Milliseconds
        ms += 15.4
        ts1 = New TimeSpan(0, 0, min, sec, ms)
    End Sub





Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        'MsgBox("Ok, Let's start")
        tmr.Start()
    End Sub





Private Sub Form2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'Dim ts As New TimeSpan(30, 0, 0, 0)
        'tmr = New System.Windows.Forms.Timer
        'tmr.Interval = 1000
        'AddHandler tmr.Tick, AddressOf Ticker_Tick
        'MsgBox("Ok, Let's start")
        'tmr.Start()
        Me.Text = "0:0"
        Dim ts As New TimeSpan(30, 0, 0, 0)
        tmr = New System.Windows.Forms.Timer
        tmr.Interval = 1
        AddHandler tmr.Tick, AddressOf Ticker_Tick
    End Sub



对我来说至关重要,对我至关重要,非常感谢.



Help Me pls, vital for me, Thankz a lot.


这篇关于运动手表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆