Results 1 to 3 of 3

Thread: delay execution of code

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2000
    Posts
    6
    i want to delay the execution of certain code for 5 min. please tell me what is the best way to do this

    amal

  2. #2
    _______ HeSaidJoe's Avatar
    Join Date
    Jun 1999
    Location
    Canada
    Posts
    3,946

    <?>

    Code:
    Option Explicit
    
    Private Declare Sub Sleep Lib "kernel32" _
    (ByVal dwMilliseconds As Long)
    
    
    Private Sub Command1_Click()
          
        Sleep 5000 'sleeps for 5 seconds
        MsgBox "Wake Up"
        
    End Sub
    "A myth is not the succession of individual images,
    but an integerated meaningful entity,
    reflecting a distinct aspect of the real world."

    ___ Adolf Jensen

  3. #3
    PowerPoster Chris's Avatar
    Join Date
    Jan 1999
    Location
    K-PAX
    Posts
    3,238
    Sleep API function is as easy as single line, but it will cause the entire application stop processing others task. So, I much more prefer to use the GetTickCount API function as below:

    Code:
    Option Explicit
    Private Declare Function GetTickCount Lib "kernel32" () As Long
    Private t1 As Long
    Private t2 As Long
    
    Private Sub DELAY(ByVal interval As Long)
    t1 = GetTickCount()
    t2 = 0
    While t2 - t1 < interval
        DoEvents
        t2 = GetTickCount
    Wend
    End Sub
    
    Private Sub Form_Load()
    'Delay 5 min
    '1 min = 60000ms
    '5 min = 120000ms
    DELAY (120000)
    MsgBox "The code have delay 5 min."
    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