VBS定时器时钟 - 输出标签

时间:2017-12-04 01:30:28

标签: vb.net visual-studio

我在Visual Studio VBS中需要一些关于此代码的帮助,我不知道如何输出文本中的所有变量。

    Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Dim timer
    Dim timer2
    Dim timer3
    Dim finaltimer
    timer = (sec.Text + 1)
    timer = Format(timer, "00")
    If timer = 60 Then
        timer = 0
        timer2 = (min.Text + 1)
        timer2 = Format(timer2, "00")
        If timer2 = 60 Then
            timer2 = 0
            timer3 = (hour.Text + 1)
            timer3 = Format(timer3, "00")
        End If
    End If
    finaltimer = timer & ":" & timer2 & ":" & timer3
    sec.Text = finaltimer
End Sub

1 个答案:

答案 0 :(得分:0)

这是jmcilhinney建议的一个简单的StopWatch方法示例:

Private SW As New Stopwatch

Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
    SW.Start()
    Timer1.Start()
End Sub

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
    Dim ts As TimeSpan = SW.Elapsed
    Label1.Text = ts.ToString("hh\:mm\:ss")
End Sub