Click to See Complete Forum and Search --> : Special timer


sahilkhan
May 21st, 2001, 12:46 AM
Hay i need to make an timer in Vb .I know now u guys will say there area lots of timer on this site.but the problem is i need timer to return me value in h:m:s just like normal watch.In short I need make an watch but I can control this watch make it start from 0:0:0

cksiow
May 21st, 2001, 01:22 AM
use a variable to keep track of the timer. like this :

dim l as long


set the timer interval to 1 second and in the timer function, put this.

l = l + 1

put a button to form and in the click event, set l = 0.

then l will always contains the time after u click the button, you can get the hour, min, and sec as below

second = l mod 60
minute = (l \ 60) mod 60
hour = l mod 3600

HTH

cksiow
http://vblib.virtualave.net - share our codes

Cakkie
May 21st, 2001, 01:27 AM
You can use the gettickcount API.

Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () as Long

Dim lStart as long

private Sub Command1_Click()
lStart = GetTickCount()
Timer1.Enabled = true
End Sub
private Sub Timer1_Timer()
dim lNow as lomg, lElapsed as Long
dim ShowTime as string, ShowHrs as Long, ShowMin as Long, ShowSec as Long
lNow = GetTickCount
' get ti;e elapsed in seconds
lElapsed = (lNow - lStart) / 1000
' hours
ShowHrs = int(lElapesed / 3600)
lElapsed = lElapsed - (ShowHrs * 3600)
' minutes
ShowMin = int(lElapesed / 60)
lElapsed = lElapsed - (ShowMin * 60)
' seconds
ShowSec = lElapsed
Label1.Caption = ShowHrs & ":" & ShowMin & ":" & ShowSec
End Sub





Tom Cannaerts
slisse@planetinternet.be

Programming today is a race between software engineers striving to build bigger and better idot-proof programs, and the universe trying to produce bigger and better idiots. So far, the universe is winning -- Rich Cook

sahilkhan
May 21st, 2001, 05:42 AM
thank for it but when I start the timmer it start from 24:2:00 some thing like this I want it to be start from 0:0:00