Magari così:
codice:
Const ESECUZIONE as Integer = 0
Const STOP as Integer = 1
Private Stato as Integer
Sub ProceduraLunga()
'Esegue lunghe operazioni
DoEvents
If Controllo() Exit Sub
'Esegue altre lunghe operazioni
DoEvents
If Controllo() Exit Sub
'Esegue altre lunghe operazioni
DoEvents
If Controllo() Exit Sub
'Esegue altre lunghe operazioni
DoEvents
If Controllo() Exit Sub
'Esegue altre lunghe operazioni
Msgbox "Finito!"
End Sub
Function Controllo() as Boolean
If Stato = STOP then
dim a as vbMsgboxResult
a = MsgBox("Sicuro di voler interrompere?",vbYesNo or vbQuestion)
If a = vbYes Then
Controllo = True
Else
Controllo = False
End If
Else
Controllo = False
End If
Stato = ESECUZIONE
End Function
Private Sub cmdAvvia_click()
Stato = ESECUZIONE
ProceduraLunga()
End Sub
Private Sub cmdStop_click()
Stato = STOP
End Sub