'THIS CODE IN A MODULE
'--------------------------------------------------
#If VB7 And Win64 Then
Private Declare PtrSafe Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
#Else
Private Declare Function GetKeyState Lib "user32" (ByVal nVirtKey As Long) As Integer
#End If
Private Const KEY_MASK As Integer = &HFF80
Public Function IsShiftKeyDown() As Boolean
IsShiftKeyDown = CBool(GetKeyState(vbKeyShift) And KEY_MASK )
End Function
'THIS CODE EMULATES THE DATA UPDATER
'-------------------------------------------------
Sub data_updater()
Do
DoEvents 'Necessary
If IsShiftKeyDown() Then
If MsgBox("SELECT OK TO STOP UPDATES", vbDefaultButton2 + vbQuestion + vbOKCancel, "BREAK FROM USER") = vbOK Then
GoTo STOP_BY_USER
End If
End If
'execute your code here
Loop
Exit Sub
STOP_BY_USER:
'if necessary, wtite here code to complete the user break
End Sub
'usage example
'---------------
Sub STARTER()
Call data_updater
End Sub
1条答案
按热度按时间vyswwuz21#
我会建议你另一种解决方案,如果用户在任何时候都存在,他按下Shift键被问到他是否要停止该过程或不,并根据答案的过程将被停止或继续.这可以在流程的任何阶段完成(我假设将在循环内实现)