Results 1 to 8 of 8

Thread: Ending program at certain time

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Bradenton, FL
    Posts
    87

    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

  2. #2
    Megatron
    Guest
    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.

  3. #3

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Bradenton, FL
    Posts
    87

    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

  4. #4
    Registered User Nucleus's Avatar
    Join Date
    Apr 2001
    Location
    So that's what you are up to ;)
    Posts
    2,530
    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.

  5. #5
    Addicted Member aturner's Avatar
    Join Date
    Nov 2000
    Posts
    179
    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

  6. #6
    Megatron
    Guest
    Or you an keep the timer in a module, by using the SetTimer API.

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jan 2001
    Location
    Bradenton, FL
    Posts
    87

    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

  8. #8
    Megatron
    Guest
    Add to a Module
    VB Code:
    1. Private Declare Function SetTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long, ByVal uElapse As Long, ByVal lpTimerFunc As Long) As Long
    2. Private Declare Function KillTimer Lib "user32" (ByVal hwnd As Long, ByVal nIDEvent As Long) As Long
    3.  
    4. Public Function TimerProc(ByVal hwnd As Long, ByVal uMsg As Long, ByVal idEvent As Long, ByVal dwTime As Long) As Long
    5.     '<--code here-->
    6.     TimerProc = 1
    7. End Function
    Usage:
    VB Code:
    1. Private Sub Form_Load()
    2.     SetTimer 0, 1, 1000, AddressOf TimerProc
    3. End Sub
    4.  
    5. Private Sub Form_Unload(Cancel As Integer)
    6.     KillTimer 0, 1
    7. 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
  •  



Click Here to Expand Forum to Full Width