xor02
Messages postés2Date d'inscriptionmercredi 17 septembre 2003StatutMembreDernière intervention18 octobre 2003
-
18 oct. 2003 à 12:21
pcpunch
Messages postés1243Date d'inscriptionmardi 7 mai 2002StatutMembreDernière intervention18 février 2019
-
19 oct. 2003 à 22:51
Salut,
j'aimerais savoir comment il faut faire pour intérompre une boucle "FOR".
Par exemple j'ai deux boutons commandes "OK" et "CANCEL". Lorsque je clique sur OK, cela lance une procédure qui comporter des boucles FOR. Imaginons que le processus dure une minute environ mais que je veuille l'interrompre avant son échéance à l'aide du bouton "CANCEL".
Comment procéder.
Même chose pour une boucle WHILE qui tourne infiniment jusqu'à un certain évènement (gestion d'interruption)
Merci bcp! ;)
pcpunch
Messages postés1243Date d'inscriptionmardi 7 mai 2002StatutMembreDernière intervention18 février 20195 18 oct. 2003 à 12:40
Voila un petit exemple :
Pour la boucle for next
Dim annul As Boolean 'Sert a stopper la boucle
Private Sub Command1_Click()'btn annulation
annul = True
End Sub
Private Sub Command2_Click()'la boucle
annul = False
For i = 0 To 100000
Label1 = i
DoEventsIf annul True Then: Label1 "annuler": Exit For
Next i
End Sub
Pour la la boucle do While
Dim annul As Boolean
Private Sub Command1_Click()
annul = True
End Sub
Private Sub Command2_Click()
annul = False
Do While annul = False
Label1 = "Boucle en cours"
DoEventsIf annul True Then: Label1 "annuler": Exit Do
Loop
End Sub
xor02
Messages postés2Date d'inscriptionmercredi 17 septembre 2003StatutMembreDernière intervention18 octobre 2003 18 oct. 2003 à 16:48
Merci pour la réponse avec exemple!
C'est dc l'instruction "exit" qui gère les intérruption...
Si j'ai bien compris, ca marcherait aussi avec un truc comme ca:
Private Sub Command2_Click()
annul = False
Do While 1=1 'toujours vrai
Label1 = "Boucle en cours"
DoEventsIf annul True Then: Label1 "annuler": Exit Do
Loop
End Sub