进程挂起: SLEEP 2000延时但不挂起: DELAY 2000================================================= Public Sub Delay(mSec As Long) On Error GoTo ShowErr
Dim TStart As Single
TStart = Timer
While (Timer - TStart) < (mSec / 1000) DoEvents Wend Exit Sub ShowErr: MsgBox Err.Source & "------" & Err.Description Exit SubEnd Sub
Sleep或WaitForSingleObject都 行。
'This project needs a button Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long) Private Sub Command1_Click() Me.Caption = "Your system will sleep 5 sec." 'Sleep for 2000 milliseconds Sleep 2000 Me.Caption = "" End Sub Private Sub Form_Load() Me.Caption = "" Command1.Caption = "Sleep ..." End Sub
Public Sub Delay(mSec As Long)
On Error GoTo ShowErr
Dim TStart As Single
TStart = Timer
While (Timer - TStart) < (mSec / 1000)
DoEvents
Wend
Exit Sub
ShowErr:
MsgBox Err.Source & "------" & Err.Description
Exit SubEnd Sub
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Private Sub Command1_Click() Me.Caption = "Your system will sleep 5 sec."
'Sleep for 2000 milliseconds
Sleep 2000
Me.Caption = ""
End Sub
Private Sub Form_Load()
Me.Caption = ""
Command1.Caption = "Sleep ..."
End Sub