Prev: Compiled If...Then does not work like in ide!
Next: Runtime Error 429 "ActiveX Component can't create object" SOLVED
From: Karl E. Peterson on 30 Jun 2010 16:52 Brain freeze here, I guess. I need a simple one-shot timer (non form-based). I was thinking, just use SetTimer, then call KillTimer in the callback. But, KillTimer fails in the callback. LastDllError=0. What quick/easy way am I forgetting for a one-shot deal like this? (Betting I need to go with mmTimers, but I've been staring at the screen for too long, and need to stretch...) Thanks... Karl -- ..NET: It's About Trust! http://vfred.mvps.org
From: Jim Mack on 30 Jun 2010 17:07 Karl E. Peterson wrote: > Brain freeze here, I guess. > > I need a simple one-shot timer (non form-based). I was thinking, > just use SetTimer, then call KillTimer in the callback. But, > KillTimer fails in the callback. LastDllError=0. > > What quick/easy way am I forgetting for a one-shot deal like this? > (Betting I need to go with mmTimers, but I've been staring at the > screen for too long, and need to stretch...) Timers are low-impact. I'd just set a flag in the callback and ignore subsequent calls. If you must kill the timer, make the ignore flag module-level and do it in the main loop (assuming you have one) based on that flag. -- Jim
From: Jim Mack on 30 Jun 2010 17:11 Karl E. Peterson wrote: > Brain freeze here, I guess. > > I need a simple one-shot timer (non form-based). I was thinking, > just use SetTimer, then call KillTimer in the callback. But, > KillTimer fails in the callback. LastDllError=0. > > What quick/easy way am I forgetting for a one-shot deal like this? > (Betting I need to go with mmTimers, but I've been staring at the > screen for too long, and need to stretch...) > > Thanks... Karl Of course, with an mmTimer, you can just create a one-shot and be done. -- Jim
From: Bob Butler on 30 Jun 2010 17:10 "Karl E. Peterson" <karl(a)exmvps.org> wrote in message news:i0gar1$ooe$1(a)news.eternal-september.org... > Brain freeze here, I guess. > > I need a simple one-shot timer (non form-based). I was thinking, just use > SetTimer, then call KillTimer in the callback. But, KillTimer fails in > the callback. LastDllError=0. works for me; what makes you think it is failing? KillTimer return value 0 is error, non-zero is success Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, _ ByVal nIDEvent As Long) As Long Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, _ ByVal nIDEvent As Long, ByVal uElapse As Long, _ ByVal lpTimerFunc As Long) As Long Public Sub StartTimer(ByVal hwnd As Long) Dim x As Long x = SetTimer(hwnd, 1, 2000, AddressOf TimerFunc) Debug.Print "Start", x, Err.LastDllError End Sub Private Sub TimerFunc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long) Dim x As Long Static k As Long k = k + 1 If k = 5 Then x = KillTimer(hwnd, idEvent) Debug.Print "Stop", x, Err.LastDllError Else Debug.Print "Fire" End If End Sub
From: Karl E. Peterson on 30 Jun 2010 17:15 Jim Mack formulated on Wednesday : > Karl E. Peterson wrote: >> Brain freeze here, I guess. >> >> I need a simple one-shot timer (non form-based). I was thinking, >> just use SetTimer, then call KillTimer in the callback. But, >> KillTimer fails in the callback. LastDllError=0. >> >> What quick/easy way am I forgetting for a one-shot deal like this? >> (Betting I need to go with mmTimers, but I've been staring at the >> screen for too long, and need to stretch...) > > Timers are low-impact. I'd just set a flag in the callback and ignore > subsequent calls. If you must kill the timer, make the ignore flag > module-level and do it in the main loop (assuming you have one) based > on that flag. Yeah, but what I got going is already complex enough, that more flags would just really make it all quite bizarre. And, I will want to reuse the timer for a later one-shot. I could just leave it running, but ideally it oughta be a very short interval on (at least) the first callback. -- ..NET: It's About Trust! http://vfred.mvps.org
|
Next
|
Last
Pages: 1 2 3 4 5 6 Prev: Compiled If...Then does not work like in ide! Next: Runtime Error 429 "ActiveX Component can't create object" SOLVED |