Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Timing how long was the system on..using Timer!! Pls Help

Status
Not open for further replies.

Fori

Programmer
Jun 18, 2003
84
MT
Hi All

I would like to know how i can get the time,being showed on the form, of how long long the form was on!! in the format 00:00:00!! i have a timer obeject but don't know how i can set it up!!

ps: is 5min 50000 or 500000msec

Thanks
Nick
 
just say in the from_load event

Option Explicit
Private lngLong As Long

Private Sub Form_Load()

lngLong = 0

Timer1.Interval = 1
Timer1.Enabled = True

End Sub


and in the Timer1_timer event :

Private Sub Timer1_Timer()

lngLong = lngLong + 1
Label1.Caption = lngLong

End Sub

then you just have to convert it into the 00:00:00 format
Try using the format function of VB
 
Setting the timer interval below 100 does not make it process the event any quicker that having the interval set at 100 on my PC.

I use the following code

Put 3 seperate labels on your form and add this code to your form. Setting the interval as 1000.

Dim intCurrSecs As Integer

Private Sub Form_Load()
Label1.Caption = 0
Label2.Caption = 0
Label3.Caption = 0
End Sub

Private Sub Timer1_Timer()
intCurrSecs = intCurrSecs + 1

If intCurrSecs < 60 Then
Label3.Caption = intCurrSecs
Else
intCurrSecs = 0
Label2.Caption = Val(Label2.Caption) + 1
End If

If Val(Label2.Caption) = 60 Then
Label2.Caption = 0
Label1.Caption = Val(Label1.Caption) + 1
End If

End Sub

Its a little long winded but works

Greg Palmer

----------------------------------------
Any feed back is appreciated.
 
ok i get this but isn't there a simpler version!! thanks nick
 
Private Sub Form_Load()
StartTime = Time
End Sub

Private Sub Form_Unload(Cancel As Integer)
EndTime = Time
Then calculate the difference
end Sub

Experience is something you don't get until just after you need it.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top