|
-
Jun 6th, 2001, 12:14 PM
#1
Thread Starter
Lively Member
Ending program at certain time
How can I write code that will shut my program down around midnight each night? I was planning on putting a timer on the Main Menu form that checks the current time every 30min and shuts down if it's 12:00am, but my program has several forms on it, and the user may leave it running on any of them. I'd rather not put a timer on every form. Any ideas?
Thanks,
Greg
-
Jun 6th, 2001, 02:40 PM
#2
As long as the Form with the Timer is open (i.e: It doesn't have to be active) then the Timer will run.
A suggestion for you is to put the interval at 60000, so your progam doesn't "have to work so hard."
Another suggestion is, when the program starts, store the current time in a variable, then calculate how long it will take to get to midnight. Next, start a timer (GetTickCount, Timer or otherwise) and when that runs out, end the program.
-
Jun 6th, 2001, 02:56 PM
#3
Thread Starter
Lively Member
Form may not be open
The Main Menu form may not be opened. The user may have any form open, but I'd rather not put the same timer on all the forms. Is there a way to do this without a timer (perhaps an API call)?
Thanks,
Greg
-
Jun 7th, 2001, 12:47 AM
#4
Registered User
As a suggestion create an ax exe that you kick off when the app loads.
The ax exe shuts down the app and itself at 12:00am.
-
Jun 7th, 2001, 05:13 AM
#5
Addicted Member
have the timer on the main form. never unload the form, just hide it
Due to the energy crisis, the light at the end of the tunnel has been turned off.
Sorry for any inconvenience this may cause
-
Jun 7th, 2001, 02:38 PM
#6
Or you an keep the timer in a module, by using the SetTimer API.
-
Jun 7th, 2001, 02:45 PM
#7
Thread Starter
Lively Member
SetTimer API syntax
Could you post the syntax for me? I see the arguments using the API text viewer, but I'm not sure what they do.
Thanks for the help,
Greg
-
Jun 7th, 2001, 02:57 PM
#8
Add to a Module
VB Code:
Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
Public Function TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long) As Long
'<--code here-->
TimerProc = 1
End Function
Usage:
VB Code:
Private Sub Form_Load()
SetTimer 0, 1, 1000, AddressOf TimerProc
End Sub
Private Sub Form_Unload(Cancel As Integer)
KillTimer 0, 1
End Sub
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
|