Results 1 to 1 of 1

Thread: Classic VB - How do I Pause my program?

  1. #1

    Thread Starter
    Banned dglienna's Avatar
    Join Date
    Jun 2004
    Location
    Center of it all
    Posts
    17,901

    Classic VB - How do I Pause my program?

    Just like the Sleep command in Quick Basic, Visual Basic also lets you delay the execution of your code.

    You do it by calling an API (Application Programming Interface) which are functions that are built into the Windows operating system.

    The one needed here is the Sleep() API, which will pause execution of your program for the specified number of milliseconds (1000ms=1 second). In this example, the program is paused for 5 seconds when you click the button.

    VB Code:
    1. Option Explicit
    2. 'This project needs a button
    3. Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
    4. Private Sub Command1_Click()
    5.     'KPD-Team 1998
    6.     'URL: [url]http://www.allapi.net/[/url]
    7.     'E-Mail: [email]KPDTeam@Allapi.net[/email]
    8.     Me.Caption = "Your system will sleep 5 sec."
    9.     'Sleep for 5000 milliseconds
    10.     Sleep 5000
    11.     Beep
    12.     Me.Caption = ""
    13. End Sub
    14.  
    15. Private Sub Form_Load()
    16.     Me.Caption = ""
    17.     Command1.Caption = "Sleep ..."
    18. End Sub

    A sample project is included below:
    Attached Files Attached Files
    Last edited by si_the_geek; Aug 31st, 2005 at 12:41 PM.

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