|
-
Nov 28th, 2006, 08:58 AM
#1
Thread Starter
Member
[RESOLVED] increase timer interval
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
-
Nov 28th, 2006, 09:01 AM
#2
Re: increase timer interval
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.
-
Nov 28th, 2006, 09:06 AM
#3
Re: increase timer interval
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
-
Nov 28th, 2006, 10:20 AM
#4
Re: increase timer interval
-
Nov 28th, 2006, 10:53 AM
#5
Re: increase timer interval
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
Last edited by CVMichael; Nov 28th, 2006 at 10:56 AM.
-
Nov 28th, 2006, 10:57 AM
#6
Re: increase timer interval
or you could use an API timer - which has a lot higher limit.
-
Nov 28th, 2006, 11:04 AM
#7
Re: increase timer interval
 Originally Posted by bushmobile
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 unexpectedly
-
Nov 28th, 2006, 11:16 AM
#8
Re: increase timer interval
 Originally Posted by CVMichael
But then you have to subclass your form, which is a lot more code, and comes with other problems, like crashing your program unexpectedly
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)
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
-
Nov 28th, 2006, 11:46 AM
#9
Thread Starter
Member
Re: increase timer interval
thank you guys ..
you have been helpful : )
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|