Results 1 to 3 of 3

Thread: [RESOLVED] Wait Method, is Microsoft example good??

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    Resolved [RESOLVED] Wait Method, is Microsoft example good??

    I'm using the wait method in one of my macro.
    I copied and pasted the exact example from the help file.


    VB Code:
    1. newHour = Hour(Now())
    2. newMinute = Minute(Now())
    3. newSecond = Second(Now()) + 10
    4. waitTime = TimeSerial(newHour, newMinute, newSecond)
    5. Application.Wait waitTime

    This is supposed to pause the macro for 10 second, but sometime it paused the macro for ever.

    I'm wondering if this method is good. Because if the macro takes for example:
    VB Code:
    1. newHour = Hour(Now())  '=10
    2. newMinute = Minute(Now()) '= 22
    3. newSecond = Second(Now()) + 10 ' = 55+10 will equal 65 witch is 05
    4. waitTime = TimeSerial(newHour, newMinute, newSecond) '=10:22:05
    5. Application.Wait waitTime


    But 10:22:05 is already passed by (the new wait time should be 10:23:05, is VBA wise enought to know that if seconds is higher thant 59 it needs to add 1 to minute???

  2. #2
    PowerPoster Static's Avatar
    Join Date
    Oct 2000
    Location
    Rochester, NY
    Posts
    9,390

    Re: Wait Method, is Microsoft example good??

    VB Code:
    1. Private Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
    2.  
    3. 'call it - its in milliseconds...
    4. Sleep 10000 '10 seconds
    JPnyc rocks!! (Just ask him!)
    If u have your answer please go to the thread tools and click "Mark Thread Resolved"

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Jan 2006
    Location
    Montreal, Canada
    Posts
    152

    Re: Wait Method, is Microsoft example good??

    thanks a lot

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