如何做VB计时器
FORM1 LOAD时就开始计时 从00:00:00开始计时
显示在TEXT1。TEXT 不需要很精确
谢了
[解决办法]
Private Sub Form_Load()
Timer1.Interval = 1000
Timer1.Enabled = True
End Sub
Private Sub Timer1_Timer()
Text1.Text = Now
End Sub
[解决办法]
- VB code
Private Sub Form_Load() Timer1.Interval = 1000 Timer1.Enabled = True End SubPrivate Sub Timer1_Timer() Text1.Text = TimeEnd Sub
[解决办法]
Option Explicit
Dim strTime As String
Private Sub Form_Load()
strTime = Now
Label1.Caption = "00:00:00"
Timer1.interval=500
timer1.enabled=true
End Sub
Private Sub Timer1_Timer()
Dim lngTime As Long
lngTime = DateDiff("s", strTime, Now)
Label1.Caption = funSecondToFormat(lngTime)
End Sub
Public Function funSecondToFormat(ByVal lngP As Long) As String
Dim strHour As String
Dim strMin As String
Dim strSec As String
strHour = Format(lngP \ 3600, "00")
strMin = Format((lngP \ 60) - (lngP \ 3600) * 60, "00")
strSec = Format(lngP Mod 60, "00")
funSecondToFormat = strHour & ":" & strMin & ":" & strSec
End Function
[解决办法]
格式化一下
- VB code
Dim StartTimePrivate Sub Form_Load() Timer1.Interval = 1000 Timer1.Enabled = True StartTime = Time End SubPrivate Sub Timer1_Timer() Dim intS As Integer intS = DateDiff("s", StartTime, Time) Text1.Text = Format(intS \ 3600, "00") & ":" & Format((intS Mod 3600) \ 60, "00") & ":" & Format(intS Mod 60, "00")End Sub