I'm quite new at vb and was wondering if someone could show me how to make a simple timer. Like have a label say "1" then "2" then "3" and so on.
Printable View
I'm quite new at vb and was wondering if someone could show me how to make a simple timer. Like have a label say "1" then "2" then "3" and so on.
Code:'in declarations
Declare Function GetTickCount Lib "kernel32" Alias "GetTickCount" () As Long
'in code
Dim t&
t=gettickcount
Do
doevents
label1=int((gettickcount-t)/1000))
loop until YouWantItToStopBooleanValue
Here is an example using the Timer function. The DoEvents lets Window's do other tasks so your computer does not freeze.
Code:Go = Timer
Do Until Timer > Go + 3
DoEvents
' place other code here
MyNum = MyNum + 1
Loop
Print MyNum
Code:Function timeout(interval)
Current = Timer
Do While Timer - Current < Val(interval)
DoEvents
Loop
End Function
'create a timer and set its interval to 100
'in the timer put:
For i = 0 to 10 'count to 10
Label1.caption = i 'count 1 to 10 showing contents on label
Timeout .01 'timeout
Next 'loop until 10
Timer1.enabled = False 'turn timer off after 10