Results 1 to 5 of 5

Thread: pause alternative ways

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Aug 2019
    Posts
    194

    pause alternative ways

    Code:
    Public Sub Pause(Seconds As Long)
        Dim start As Single
        start = Timer
        Do
            If Abs(Timer - start) > Seconds Then Exit Sub
            DoEvents
        Loop
    End Sub
    pause 1 'looking to se many other ways this can be done so the app don't freeze up while it counts down,looking for something that run's smoothly.

  2. #2
    Hyperactive Member
    Join Date
    Aug 2017
    Posts
    348

    Re: pause alternative ways

    Try the Wait Demo.zip attachment here.

  3. #3
    PowerPoster
    Join Date
    Sep 2006
    Location
    Egypt
    Posts
    2,580

    Re: pause alternative ways

    Quote Originally Posted by doberman2002 View Post
    Code:
    Public Sub Pause(Seconds As Long)
        Dim start As Single
        start = Timer
        Do
            If Abs(Timer - start) > Seconds Then Exit Sub
            DoEvents
        Loop
    End Sub
    pause 1 'looking to se many other ways this can be done so the app don't freeze up while it counts down,looking for something that run's smoothly.
    Your mistake is declaring Seconds param as Long instead of Single, so if you call it with 0.1, it will be round to 0 and call it with 0.6, it will be round to 1

    Try this optimized code
    Code:
    Public Sub Pause(Seconds As Single)
        Dim start As Single
    
        start = Timer + Seconds
        Do
            DoEvents
        Loop Until Timer > start
        
    End Sub
    Last edited by 4x2y; Sep 21st, 2019 at 03:52 PM.



  4. #4
    PowerPoster
    Join Date
    Feb 2006
    Posts
    21,194

    Re: pause alternative ways

    If you want code to run after a "pause" then trigger it using a Timer control. That's why we have them.

    DoEvents() function calls can be hazardous and often result in re-entrancy and data corruption or loss.

  5. #5
    PowerPoster
    Join Date
    Feb 2017
    Posts
    2,389

    Re: pause alternative ways

    If the pause is short, you can use Sleep:

    Code:
    Private Declare Sub Sleep Lib "Kernel32" (ByVal dwMilliseconds As Long)
    
    Sleep 100

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