hi
the max interval that can be used for a timer is about 64,000 milliseconds wich is about a minute.. is there a way to increase that like using multiple intervals or something ?
thnx
Printable View
hi
the max interval that can be used for a timer is about 64,000 milliseconds wich is about a minute.. is there a way to increase that like using multiple intervals or something ?
thnx
You can not able to increase the timer interval but you can use the counter for it. Use an integer variable and count it and whenever it get a specific number then you can use the timer.
And here's how (just change myInterval to whatever seconds you'd like):VB Code:
Option Explicit Private myInterval As Integer Private Sub Form_Load() myInterval = [B]180[/B] '3 minutes for example With Timer1 .Interval = 1000 'a second .Enabled = True End With End Sub Private Sub Timer1_Timer() Static seconds As Integer seconds = seconds + 1 If seconds = myInterval Then seconds = 0 Debug.Print "Interval" End If End Sub
Check this link:
How to use timer control for more than 65,535 milliseconds
I know this is more code, but it is also more precise, and also the timer does not execute very often (like every second)
ALSO... the event will always fire at the same interval (MyInterval) even if the code in the event takes a long time (but less than MyInterval)
VB Code:
Option Explicit Private Declare Function GetTickCount Lib "kernel32" () As Long Private myInterval As Long, StartTick As Long Private Const MaxTimerInterval As Long = 65000 ' Actually max interval is 65535 Private Sub Form_Load() ' Set the interval myInterval = 180 * 1000& ' 180 seconds, 3 minutes... StartTick = GetTickCount Timer1.Enabled = True Timer1.Interval = 1 End Sub Private Function lngMIN(N1 As Long, N2 As Long) As Long If N1 < N2 Then lngMIN = N1 Else lngMIN = N2 End If End Function Private Sub Timer1_Timer() Dim TimeLeft As Long TimeLeft = myInterval - (GetTickCount - StartTick) If TimeLeft <= 0 Then StartTick = GetTickCount TimerEvent ' Execute the timer event TimeLeft = myInterval - (GetTickCount - StartTick) End If Timer1.Interval = lngMIN(TimeLeft, MaxTimerInterval) End Sub Private Sub TimerEvent() ' Put your code to execute at timer event End Sub
or you could use an API timer - which has a lot higher limit.
But then you have to subclass your form, which is a lot more code, and comes with other problems, like crashing your program unexpectedlyQuote:
Originally Posted by bushmobile
you don't need to subclass your program - you pass the address of a sub to SetTimer and any WM_TIMER messages are passed through it (you can also process the WM_TIMER messages through WndProc, but you don't have to)Quote:
Originally Posted by CVMichael
and it doesn't crash your program unexpectantly - it crashes it when it hits unhandled errors - if your program is running fine then any subclassing / API timer / etc. won't cause you any trouble - just gotta remember to save often :)
thank you guys ..
you have been helpful : )