Results 1 to 4 of 4

Thread: Help with a pausing function...

  1. #1

    Thread Starter
    New Member
    Join Date
    May 2000
    Location
    Illinois, USA
    Posts
    3

    Question

    Hey all, a quick question here. I found this function on Planet Source Code which let's you sort of pause the program, but not completely stop it. I use this function in my winsock control code so I can send out several pieces of data without having them all overlap and what not.

    Now, I've been using this function, as I said, in the form of "timedPause 1". But, now that my program is nearing completion and almost ready for beta test, this one second pause is becoming too large. Basically, all I'm needing is just a few miliseconds of time to pass, but this function only gives me the option of a minimum of that one second.

    Can anyone tell me how to modify this function so I can 'freeze' for miliseconds instead of seconds? I'd greatly appreciate it, thanks.

    Code:
    Option Explicit
    Public exitPause As Boolean
    
    
    Public Function timedPause(secs As Long)
        Dim secStart As Variant
        Dim secNow As Variant
        Dim secDiff As Variant
        Dim Temp%
        
        exitPause = False 'this is our early way out out of the pause
        
        secStart = Format(Now(), "mm/dd/yyyy hh:nn:ss AM/PM") 'get the starting seconds
        
    
    
        Do While secDiff < secs
            If exitPause = True Then Exit Do
            secNow = Format(Now(), "mm/dd/yyyy hh:nn:ss AM/PM") 'this is the current time and Date at any itteration of the Loop
            secDiff = DateDiff("s", secStart, secNow) 'this compares the start time With the current time
            Temp% = DoEvents
        Loop
    End Function
    - Evan (Okaria)

  2. #2
    Guest
    Try one of these:

    Code:
    Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)   
    
    To delay the program for 1 second, use this code:
    
    Call Sleep(1000)
    Or:

    Code:
    Function timeout(interval)
    Current = Timer
    Do While Timer - Current < Val(interval)
    DoEvents
    Loop
    End Function
    
    Timeout .1

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238

    Thumbs down GetTickCount

    Don't use the Sleep API function, because it will stop processing others application as well. So all you need is to create your own pause function with the GetTickCount API function.

    Code:
    Option Explicit
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Private t1 As Long
    Private t2 As Long
    
    Private Sub Pause(ByVal PAUSE_INTERVAL As Long)
    t1 = GetTickCount
    t2 = 0
    Do While t2 - t1 < PAUSE_INTERVAL
        DoEvents
        t2 = GetTickCount
    Loop
    End Sub
    
    Private Sub Command1_Click()
    'Pause for 5 second
    Pause 5000
    End Sub

  4. #4
    Frenzied Member Mark Sreeves's Avatar
    Join Date
    Nov 1999
    Location
    UK
    Posts
    1,845
    use the timer function


    this is straight out of the VB help files:
    Code:
    Dim PauseTime, Start, Finish, TotalTime
    If (MsgBox("Press Yes to pause for 5 seconds", 4)) = vbYes Then
    	PauseTime = 5	' Set duration.
    	Start = Timer	' Set start time.
    	Do While Timer < Start + PauseTime
    		DoEvents	' Yield to other processes.
    	Loop
    	Finish = Timer	' Set end time.
    	TotalTime = Finish - Start	' Calculate total time.
    	MsgBox "Paused for " & TotalTime & " seconds"
    Else
    	End
    End If

    If it pauses across midnight though, it will never exit the loop
    Mark
    -------------------

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