|
-
Nov 16th, 2000, 10:42 PM
#1
Thread Starter
Addicted Member
How do I code a timer to count down to 2 minutes after inactivity?
P.S. keeping resource usage low is the goal here?
I appreciate all of your time and effort,
Daniel Christie
VB 5 and 6 Enterprise Editions,
Html, Java scipt, Vb script,
& etc...
http://www.qwcd.com
-
Nov 16th, 2000, 11:07 PM
#2
Try this:
Code:
Sub Pause(Interval As Integer)
Start = Timer
Do While Timer < Start + Interval
DoEvents
Loop
End Sub
Private Sub Command1_Click()
Label1.Caption = "120"
Do Until Label1.Caption = "0"
Label1.Caption = Label1.Caption - 1
DoEvents
Pause 1
Loop
End Sub
-
Nov 17th, 2000, 12:02 AM
#3
Frenzied Member
You can get Windows to run a timer (or as many timers as you have memory for) for you. I don't know how to do it in VB, because I've only ever seen it in C, but I expect there's a way of getting it in VB.
It's a callback function, so I guess you could use the AddressOf operator to send a pointer to a function that will handle the timer's event. Here's the prototype in C:
Code:
UINT SetTimer(HWND hWnd, // handle to parent window
UINT nIDevent, // timer ID
UINT nElapse, // timer delay in milliseconds
TIMERPROC lpTimerFunc); // timer callback
In case you don't know what all that means, basically if it was written in VB it would be:
Code:
Function SetTimer(hWnd As HWnd, _ ' handle to parent window
nIDevent As Integer, _ ' timer ID
nElapse As Integer, _ ' timer delay in milliseconds
lpTimerFunc As TIMERPROC _ ' timer callback
) As Integer
Except the integers are actually meant to be unsigned.
lpTimerProc might look a bit odd; basically you pass the address of your function that you want to be triggered when your timer event fires. nIDevent is an ID number you assign this timer so that you can destroy it afterwards. nElapse is, as you might have guessed, the length of time in milliseconds between each firing of your timer. hWnd is the handle of the parent window (you can use your main form) so you can send something like Form1.hWnd in that.
You need to destroy the timer when you've finished with it, using the KillTimer function:
Code:
BOOL KillTimer(HWND hWnd, // handle of window
UINT uIDevent); // timer ID
Hey this might be of absolutely no use whatsoever to you, but at least you know that Windows provides timers if you need them.
[Edited by HarryW on 11-17-2000 at 12:05 AM]
Harry.
"From one thing, know ten thousand things."
-
Nov 17th, 2000, 12:25 AM
#4
transcendental analytic
Well Harry, just search for Settimer and you'll find, i know, i'm just too tired to search for it hehe, well pu this in a settimer proc or a timer event:
Code:
If CheckActivity > 120000 Then MsgBox "Inactivity for 120 seconds"
And then you notice CheckActivity isn't a valid vb function so you have to use mine instead:
Code:
Private Declare Function GetAsyncKeyState Lib "user32" (ByVal vKey As Long) As Integer
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private Declare Function GetCursorPos Lib "user32" (lpPoint As POINTAPI) As Long
Private counter As Long
Private Type POINTAPI
x As Long
y As Long
End Type
Function CheckActivity() As Long
Static oldk As Long, oldm As POINTAPI, newm As POINTAPI, counter
Dim newk&, n&
For n = 0 To 255
newk = newk + GetAsyncKeyState(n)
Next n
GetCursorPos newm
If newk <> oldk Or newm.x <> oldm.x Or newm.y <> oldm.y Or counter = 0 Then counter = GetTickCount
CheckActivity = GetTickCount - counter
oldm = newm: oldk = newk
End Function
Use  
writing software in C++ is like driving rivets into steel beam with a toothpick.
writing haskell makes your life easier:
reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.
-
Nov 17th, 2000, 02:16 AM
#5
Thread Starter
Addicted Member
Thanks guys,
You all had great suggestions. I ended up using Kedaman's coding, It worked like a real charm.
Thanks guys, I really do appreciate it.
I appreciate all of your time and effort,
Daniel Christie
VB 5 and 6 Enterprise Editions,
Html, Java scipt, Vb script,
& etc...
http://www.qwcd.com
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
|