i want to delay the execution of certain code for 5 min. please tell me what is the best way to do this
amal
Printable View
i want to delay the execution of certain code for 5 min. please tell me what is the best way to do this
amal
Code:Option Explicit
Private Declare Sub Sleep Lib "kernel32" _
(ByVal dwMilliseconds As Long)
Private Sub Command1_Click()
Sleep 5000 'sleeps for 5 seconds
MsgBox "Wake Up"
End Sub
Sleep API function is as easy as single line, but it will cause the entire application stop processing others task. So, I much more prefer to use the GetTickCount API function as below:
Code:Option Explicit
Private Declare Function GetTickCount Lib "kernel32" () As Long
Private t1 As Long
Private t2 As Long
Private Sub DELAY(ByVal interval As Long)
t1 = GetTickCount()
t2 = 0
While t2 - t1 < interval
DoEvents
t2 = GetTickCount
Wend
End Sub
Private Sub Form_Load()
'Delay 5 min
'1 min = 60000ms
'5 min = 120000ms
DELAY (120000)
MsgBox "The code have delay 5 min."
End Sub