Boucle et sequencement en visual basic

pythagore1 Messages postés 25 Date d'inscription   Statut Membre Dernière intervention   -  
Milou2211 Messages postés 35 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,
regarder ce code:

Private Sub Command4_Click()
Dim tempo As Long
Dim tempo1 As Long

If Command4.Caption <> "Lecture Auto A" Then
Command4.Caption = "Lecture Auto A"
'Else
'Command4.Caption = "Arret"
'End If

Do While Command4.Caption = "Lecture Auto A"
Form1.StatusBar1.SimpleText = "Q: MA"
Call Connexion(Form1) 'envoi de la barre de status
Call reception 'on met ds utile ce qu'on recoit
If utile = "" Then
Exit Sub

End If

If utile <> "" Then
If Mid(utile, 2, 1) = "a" Then
Text2.Text = "La liste des defauts a été modifiée"
End If
If Mid(utile, 2, 1) = "A" Then
Text2.Text = ""
End If
End If

Nbcompteurs = Val("&H" & Mid(utile, 3, 2))
For i = 1 To Nbcompteurs
Text1(i - 1) = Mid(utile, (i * 2) + 3, 2)
Next
For i = Nbcompteurs To 15
Text1(i) = "**"
Next
If Command4.Caption <> "Lecture Auto A" Then
Command4.Caption = "Lecture Auto A"
End If

If Command4.Caption <> "Lecture Auto A" Then
Command4.Caption = "Arret"
End If

tempo = Timer + 5
Do While Timer < tempo
Loop
'If Command4.Caption = "Lecture Auto A" Then
'info = MsgBox(tempo, vbInformation)
'End If
Loop

End If
End Sub

Le prbleme est que mon bouton "arret" censé apparaitre apres le clique du bouton "Lecture Auto A" n'apparait pas et kan je clique sur "Lecture Auto A" ça boucle sans fin et pour arreter je dois fermer l'ordinateur je ne sais plus koi faire avec ces sequencements, J'ai besoin de votre aide.
A voir également:

2 réponses

michel_m Messages postés 16602 Date d'inscription   Statut Contributeur Dernière intervention   3 314
 
Bonjour,

If Command4.Caption <> "Lecture Auto A" Then
Command4.Caption = "Arret"
End If

tempo = Timer + 5
Do While Timer < tempo

remplaces Command4.Caption <> "Lecture Auto A" par Command4.Caption = "Lecture Auto A"

mais comme il y a appel de procédures et qu'on ne sait ce qu'il s'y passe, il est difficile d'affirmer que c'est la bonne solution
1
Milou2211 Messages postés 35 Date d'inscription   Statut Membre Dernière intervention   11
 
Il me semble que les 2 derniers loop sont en trop, non ?

la fin des boucles WHILE doit se terminer pour chacune par WEND. Tu n'as pas une rreur de syntaxe à l'exécution ?


nbcompteurs devrait être testé <15 avant de démarrer la boucle FOR I = NBCOMPTEURS TO 15
idem au-dessus for i=1 to nbcompteurs. nbcompteurs doit être >1.
-1