VB Tips Vol.02
Windows起動後の経過時間を表示する


Windows起動後の経過時間を表示するにはGetTickCount関数を使用します。結果はミリ秒で返されるのでわかりやすいように変換してあります。

Private Declare Function GetTickCount Lib "kernel32.dll" () As Long

Private Sub Timer1_Timer()
Dim RetCount As Long
Dim h As Integer, m As Integer, s As Integer, ms As Integer
RetCount = GetTickCount 'ミリ秒単位で返ってきます
'
h = RetCount \ 1000 \ 60 \ 60
m = RetCount \ 1000 \ 60 - h * 60
s = RetCount \ 1000 - (h * 60 * 60 + m * 60)
ms = RetCount Mod 1000

Label1.Caption = "経過時間 " & Right(("0" & h), 2) & ":" _
& Right(("0" & m), 2) & ":" & Right(("0" & s), 2) & "." _
& Right(("00" & ms), 3)
End Sub

サンプルプログラムのダウンロード(5.51KB)
※このページの内容とサンプルプログラムのコードは多少異なる場合があります。


戻る ホーム