Quantcast
Channel: VBForums - CodeBank - Visual Basic 6 and earlier
Viewing all articles
Browse latest Browse all 1448

Visual Basic Advance Timer

$
0
0
Did you coded or experienced a timer with more then 60 seconds interval
or a timer with maximum cap limit ?

Here it all now :

Functions:-
  1. Intervals 1 , 5 , 10 and 15 minutes
  2. Maximum Timer Life 1 , 2 ,3 and infinity hours


Name:  TimerCodePreview.jpg
Views: 63
Size:  45.5 KB

Code:
Code:

Public Function StartTimer(bInterval As Double, Optional bMax As Double)
Dim MiliCounter  As Double, Infinity As Boolean
If bMax = 0 Then
Infinity = True
End If
mMax = bMax ‘Maximum Second , -1 for infinity
mInterval = bInterval ‘Interval Second
MiliCounter = -1 ‘bypass millisecods (timer is for seconds only)
StartTime = GetTickCount() ‘Get currunt system timer tick
Do While TimerEnabled = True
TimePassed = Int((GetTickCount() – StartTime) / 1000) ‘Convert to seconds
If Infinity = False Then
If TimePassed > mMax Then TimerEnabled = False ‘look for Maximum Second
End If
If (TimePassed Mod mInterval = 0) And (TimePassed > MiliCounter) Then
‘TimePassed Mod mInterval = 0  ‘look for Interval Second
‘TimePassed > MiliCounter      ‘look for next second
MiliCounter = TimePassed
‘/////////////Main Interval Code////////////
Debug.Print “time consumed “; TimePassed
Call InvokeIntervalEvent
‘///////////////////////////////////////////
End If
DoEvents
Loop
End Function

Call the function as This:
call StartTimer( 1 * 60, 1 * 3600)
i.e StartTimer for 60 sec intervel and 1 hour life

Happy Coding…:)


Example is coded in following Post
Attached Images
 

Viewing all articles
Browse latest Browse all 1448

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>