Share via


Timer 屬性

更新:2007 年 11 月

傳回表示從午夜後所經過秒數的 Double 值。

ReadOnly Public Property Timer() As Double

備註

Timer 屬性會傳回午夜過後的秒數和毫秒數。秒數是傳回值的整數部分,毫秒則是小數部分。

範例

這個範例會使用 Timer 屬性,來暫停應用程式。它可以在暫停期間執行其他處理。

Public Sub waitFiveSeconds()
    If TimeOfDay >= #11:59:55 PM# Then
        MsgBox("The current time is within 5 seconds of midnight" & _
            vbCrLf & "The timer returns to 0.0 at midnight")
        Return
    End If
    Dim start, finish, totalTime As Double
    If (MsgBox("Press Yes to pause for 5 seconds", MsgBoxStyle.YesNo)) _
        = MsgBoxResult.Yes Then
        start = Microsoft.VisualBasic.DateAndTime.Timer
        ' Set end time for 5-second duration.
        finish = start + 5.0
        Do While Microsoft.VisualBasic.DateAndTime.Timer < finish
        ' Do other processing while waiting for 5 seconds to elapse.
        Loop
        totalTime = Microsoft.VisualBasic.DateAndTime.Timer - start
        MsgBox("Paused for " & totalTime & " seconds")
    End If
End Sub

請注意,您必須利用 Microsoft.VisualBasic 命名空間 (Namespace) 來限定 Timer 屬性,因為 Timer 也是 System.ThreadingSystem.TimersSystem.Windows.Forms 命名空間中的已定義類別。

需求

命名空間Microsoft.VisualBasic

**模組︰**DateAndTime

組件 (Assembly):Visual Basic Runtime Library (在 Microsoft.VisualBasic.dll 中)

因為 Timer 是模組中的成員,而不是類別中的成員,因此不需要建立物件來存取 Timer。

請參閱

參考

Randomize 函式 (Visual Basic)

TimeOfDay 屬性

Today 屬性

System

System.Windows.Forms

DateTime

ArgumentException

ArgumentOutOfRangeException