Results 1 to 4 of 4

Thread: Is there a command to make a program pause for a specified number of seconds?

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Jan 2001
    Location
    California
    Posts
    203

    Is there a command to make a program pause for a specified number of seconds?

    Like in Q-basic where you can give the "Sleep" command. Is there something similar in vb.

    I know you can do it with a timer/ Is there any other way, or is there just a "Sleep" command. I want my program to pause for 5 seconds.

    Thanks,
    M

  2. #2
    Frenzied Member Mega_Man's Avatar
    Join Date
    Mar 2001
    Location
    North of England, South-East of Iceland
    Posts
    1,067
    Place this in a module
    VB Code:
    1. Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)
    And the command to use is
    VB Code:
    1. Sleep (5000) ' This is 5 seconds
    Mega.
    "If at first you don't succeed, then skydiving is not for you"

  3. #3
    Addicted Member Pickler's Avatar
    Join Date
    May 2001
    Location
    nffanb
    Posts
    248
    There is a Sleep API
    VB Code:
    1. Public Declare Sub Sleep Lib "kernel32" Alias "Sleep" (ByVal dwMilliseconds As Long)

  4. #4
    Frenzied Member
    Join Date
    Aug 2001
    Posts
    1,075
    While Sleep will work you may find that it is disruptive because it seems to lock up your program. Another way is to use an idle loop.


    VB Code:
    1. 'Call in miliseconds
    2. '1000 milsecs = 1 sec
    3. OneSecond 10000
    4.  
    5. Public Sub OneSecond(iInterval As Long)
    6.     Dim lStart As Long
    7.     lStart = GetTickCount()
    8.     While GetTickCount() - lStart < iInterval
    9.         DoEvents
    10.     Wend    
    11. End Sub

    Greg
    Free VB Add-In - The Reference Librarian
    Click Here for screen shot and download link.

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