Results 1 to 8 of 8

Thread: [RESOLVED] How to make the program loop and sleep

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2009
    Location
    IRaQ / BaghDaD
    Posts
    192

    Resolved [RESOLVED] How to make the program loop and sleep

    hi



    how to make program loop the job and after that sleep for 15 min
    and after 15 min start again and do the job and after that sleep again


  2. #2
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to make the program loop and sleep

    try using a timer to keep track of the current system time and preform operation every 15 minutes
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2009
    Location
    IRaQ / BaghDaD
    Posts
    192

    Re: How to make the program loop and sleep

    can u give me example

  4. #4
    PowerPoster
    Join Date
    Dec 2004
    Posts
    25,618

    Re: How to make the program loop and sleep

    in your timer event
    vb Code:
    1. Static startime As Date
    2. If startime = "12:00:00 AM" Then startime = Now 'to set a value first timer run
    3. If Now > startime Then dostuff ' run some other procedure
    4. startime = DateAdd("n", 15, Now) 'reset startime 15 minutes later
    you can set the timer interval to approx 1 minute (60000)
    i do my best to test code works before i post it, but sometimes am unable to do so for some reason, and usually say so if this is the case.
    Note code snippets posted are just that and do not include error handling that is required in real world applications, but avoid On Error Resume Next

    dim all variables as required as often i have done so elsewhere in my code but only posted the relevant part

    come back and mark your original post as resolved if your problem is fixed
    pete

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2009
    Location
    IRaQ / BaghDaD
    Posts
    192

    Re: How to make the program loop and sleep

    is run with time

    i want it the program run every 15 min and sleep 15 and run again

    hope u got it

  6. #6
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to make the program loop and sleep

    Have you tried the code? Add a timer to your form and copy & paste sample code as suggested.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  7. #7

    Thread Starter
    Addicted Member
    Join Date
    Nov 2009
    Location
    IRaQ / BaghDaD
    Posts
    192

    Re: How to make the program loop and sleep

    i did it and if the time is not 12:00:00 the code not running

    i must put time with it like run my program in after 15 when time will be 2:00:00 PM

    and i want it like this

    i want my program do his job and sleep for 15 min and do his job again ....etc

    i hope u got it

  8. #8
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: How to make the program loop and sleep

    With the code that westconn1 provided, the 1st time the timer event is triggered, it will set the 15 minute marker exactly 15 minutes later, then "do stuff" when that marker elapses, set the next 15 minute marker, etc, etc. Did you enable your timer and give it a non-zero interval? If not, do that.

    Here is another option if you want to dictate when the 1st event will occur or you start/stop your timer.

    1. Declare a new variable at top of your form: Dim targetTime As Date
    2. Be sure to set your timer's interval property to something like 30 seconds. Enabled=False
    3. In your button click or whatever you use to start/stop the timer
    :: When starting, set targetTime to the date/time when the 1st event should be run and enable your timer
    :: When stopping, disable your timer
    4. The timer event would look like this
    Code:
    If Now() => targetTime Then
       ' disable the timer
       ' call your routine that must be run
       targetTime = DateAdd("n", 15, Now())
       ' re-enable the timer
    End If
    As you can see there isn't much difference between the 2 methods.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

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