|
-
Jul 26th, 2000, 06:00 PM
#1
Thread Starter
New Member
Thanx for reading my thread...
When using the Timer.. The time interval value is between 0 to 65,535.. is there any way to get the timer event to fire between 0 to 7,200,000??? Cause i want it to fire every 2 hours or less?? Suggestions would be appreciated! =)
-
Jul 26th, 2000, 06:17 PM
#2
You can create your own timer using the Timer function.
Code:
Private Sub TimeCheck(Interval As Long)
Start = Timer
'Loop until the number of seconds in "Interval" has passed by
Do While Timer < Start + Interval
DoEvents
Loop
End Sub
Private Sub Command1_Click()
'Wait 2 hours then display a MessageBox
TimeCheck (7200)
MsgBox ("Time is up")
End Sub
-
Jul 26th, 2000, 06:37 PM
#3
Hyperactive Member
I'm pretty certain that the SetTimer API doesn't have this restriction. I know that it will at least run to 70,000. Give this a try:
****************Put this code in a module***************
Code:
Public Declare Function SetTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Public Declare Function KillTimer Lib "user32.dll" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Const WM_TIMER = &H113
Public Sub TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, _
ByVal dwTime As Long)
MsgBox "It is now 70 Seconds"
'you can call the cleanup here, or call it from the form.
'Just make sure you call it, or your program will crash
Call TimerCleanup(hwnd)
End Sub
Private Sub TimerCleanup(ByVal hwnd As Long)
Dim lret As Long
lret = KillTimer(hwnd, 1)
End Sub
*******************Code for Form********************
Code:
Private Sub Command1_Click()
Dim tval as long
tval = SetTimer(Me.hwnd, 1, 70000, AddressOf TimerProc)
End Sub
And that should do it.
Hope this helps.
-
Jul 26th, 2000, 07:09 PM
#4
Thread Starter
New Member
I'm pretty new at this so i'm just trying to understand here
Magatron: I'm assuming that in the
Private Sub TimeCheck(Interval As Long)
You are creating a New Timer Control and calling it "Start"
(Snip of your code below)
'Loop until the number of seconds in "Interval" has passed by
Do While Timer < Start + Interval
DoEvents
Loop
-- So this is kidda like a busy waiting loop right?
(Snip of your code below)
Private Sub Command1_Click()
'Wait 2 hours then display a MessageBox
TimeCheck (7200)
MsgBox ("Time is up")
End Sub
-- So here, after user clicks on the command, basically it'll wait for 2 hours doing things in the "DoEvent" then print the message?
-- I'm just starting so i'm not totally sure about things yet...
-
Jul 26th, 2000, 07:13 PM
#5
Thread Starter
New Member
reeset :
(snip of your code below)
Dim tval as long
tval = SetTimer(Me.hwnd, 1, 70000, AddressOf TimerProc)
-- Is tval a special name that means the time of the interval it stores? And I was wondering how i know the Address for the TimerProc?
Thanx for responding to my post magatron and reeset =)
-
Jul 26th, 2000, 07:20 PM
#6
Thread Starter
New Member
Hello, i just read about the Timer.setInterval :
public final synchronized void setInterval( int value )
-- So it takes an int values, which means that it can go up to 7,200,000 right? so if i go :
public final synchronized void setInterval(7200000)
-- Then theoritically i will get a timer event happening every 2 hours? I want the event cause i want it to do other things all the time but only something else every 2 hours?
-
Jul 27th, 2000, 12:02 AM
#7
Hyperactive Member
Fragile:
Quickly, the tval in
Code:
Dim tval as long
tval = SetTimer(Me.hwnd, 1, 70000, AddressOf TimerProc)
isn't special in anyway. It is just a variable I used to hold the returned integer. If the function is successful, it returns a 1 and if it is unsuccessful, it returns a zero.
Also, the Addressof is a pointer function. If points a named public function in a module. So as long as you have the TimeProc in a module (any module in the project), the Addressof operator will find it.
Hope this answers your questions.
-
Jul 27th, 2000, 04:40 PM
#8
Thread Starter
New Member
Reeset:
Yes.. thanx for the explaination.. i have a much better idea now!! =)
-
Jul 27th, 2000, 04:49 PM
#9
Fragile, I was actually creating a sub called TimeCheck, not a control. The variable Start is stored when the function is called, so we have a starting time of when the sub was called hence we can determine when 2 hours is from then.
So this is kidda like a busy waiting loop right?
Yes, that loop, in a sense pauses the sub until the number of seconds specified in the Interval argument have passed by.
Regarding your last question, yes, it will wait until 2 hours have passed by then it will continue execution of the sub.
-
Jul 27th, 2000, 05:09 PM
#10
Thread Starter
New Member
Magatron:
Thanx for getting back to me..
Actually, I'm trying to find a way to call an event every 2 hours.. and not have it stop and wait..
When i use :
timer.Interval = (setting the interval here in ms)
it will fire the timer event to whatever i set, however, it's only up to about 65sec. at most...
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
|