PDA

Click to See Complete Forum and Search --> : Classic VB - How do I Pause my program?


dglienna
Aug 31st, 2005, 01:36 AM
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.

Option Explicit
'This project needs a button
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
'KPD-Team 1998
'URL: http://www.allapi.net/
'E-Mail: KPDTeam@Allapi.net
Me.Caption = "Your system will sleep 5 sec."
'Sleep for 5000 milliseconds
Sleep 5000
Beep
Me.Caption = ""
End Sub

Private Sub Form_Load()
Me.Caption = ""
Command1.Caption = "Sleep ..."
End Sub


A sample project is included below: