Win32API Example - Sleep
Language(s):Visual Basic 6.0
Category(s):API

Using the Sleep API.

' Win32API Examle - Sleep 
'
' Jon Vote 02/2002 

' 1) Create a new project. Form1 will be created by default.
' 2) Add a Command Button to the form. 
' 3) Paste the following code into the declarations section of Form1:

' --- Begin code for Form1 ---

Option Explicit

Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)

Private Sub Form_Load()
  
  Me.Caption = "Win32API - Sleep Example"
  Command1.Caption = "&Sleep"
  
End Sub

Private Sub Command1_Click()

 Dim lngMiliSeconds As Long
 lngMiliSeconds = Val(InputBox$("Sleep for how long (Miliseconds)?", "Sleep Example", 2000))
 
 If MsgBox("Sleep for " & lngMiliSeconds & " miliseconds?", vbOKCancel, "Sleep") = vbOK Then
    Cls
    Print "Now is: " & Now
    Print "Sleeping until: " & DateAdd("s", lngMiliSeconds / 1000, Now)
    DoEvents
    Sleep lngMiliSeconds
    MsgBox "Done"
 End If
 
End Sub

Private Sub Form_Unload(Cancel As Integer)
  End
End Sub

' --- End code for Form1 ---


This article has been viewed 4192 times.
The examples on this page are presented "as is". They may be used in code as long as credit is given to the original author. Contents of this page may not be reproduced or published in any other manner what so ever without written permission from Idioma Software Inc.