Home > Software engineering >  Want to delay but still want to exit the delay at any time, please help improve the code, now can�
Want to delay but still want to exit the delay at any time, please help improve the code, now can�

Time:10-11

 Public duan As Boolean 'breakpoints 

Public Function Sleep2 (T As Long)
Dim Savetime As Long
Dim TTTTT As Boolean
Savetime=timeGetTime '
note at the beginning of timeThe Do While timeGetTime & lt; Savetime + T 'circular wait
TTTTT=duan
If TTTTT=False Then the Exit Function
If TTTTT=False Then Label6. Caption="retired sleep2"
DoEvents' transfer of control
Loop
End the Function

CodePudding user response:

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

Private Const iSeparator As Long=50 'once every 200 milliseconds to check whether the user has ordered the interrupt;


Private Sub CommandButton1_Click ()
CallSleep
End Sub



Private Sub callSleep ()
Dim beginTime As Long
Dim theTime As Long

BeginTime=GetTickCount ()

The Do While True
TheTime=GetTickCount ()
If beginTime + iSeparator & lt; TheTime Then
If CheckBox1. Value=https://bbs.csdn.net/topics/True Then
The Exit Sub
End the If
BeginTime=theTime
Label1. Caption=Str (theTime)
Sleep iSeparator
End the If
DoEvents
Loop
End Sub


Sorry, the time relationship, can't test the,,,

CodePudding user response:

Hello, thank you,
CallSleep can take parameters? I need to stop a specified time, and then continue with the following statement
  • Related