cs_Julien39
Messages postés6414Date d'inscriptionmardi 8 mars 2005StatutModérateurDernière intervention29 juillet 2020
-
28 juin 2005 à 18:11
Gobillot
Messages postés3140Date d'inscriptionvendredi 14 mai 2004StatutMembreDernière intervention11 mars 2019
-
29 juin 2005 à 20:25
Je veux faire un programme utilisant deux boucles et je ne me suis pas encore bien adapté à cet outil quand je l'execute : Reference variable de controle next incorrecte. Et le i de Next i est surligné, je vous donne l'integralité de mon code
Private Sub Command1_Click()
Dim a, b, c, d As Integer
a = Text1.Text
b = Text2.Text
c = Text3.Text
If c = 0 Then
Label2.Caption = 0
Label3.Caption = 0
ElseIf a = 0 Then
Label2.Caption = 1
Label3.Caption = c
ElseIf b = 0 Then
Label2.Caption = c
Label3.Caption = 1
Else: For i = -100 To 100
For n = -100 To 100
If a * i + b * n = c Then
Label2.Caption = i
Label3.Caption = n
Exit For
Exit For
End If
mrdep1978
Messages postés402Date d'inscriptionjeudi 25 novembre 2004StatutMembreDernière intervention 7 juin 20097 28 juin 2005 à 18:54
J'ai repris ton code et après qqes pttes modif ça marche.
J'ai essayé aussi en utilisant des boucles While (parce que le double Exit For, je ne suis pas fan)
Pour DARKSIDIOUS : Il sort de sa boucle quand la condition est validée, donc pour moi le DoEvents ne change rien
Private Sub Command1_Click()
Dim a As Integer
Dim b As Integer
Dim c As Integer
Dim i As Integer
Dim n As Integer
Dim lb_Trouve As Boolean
a = Text1.Text
b = Text2.Text
c = Text3.Text
If c = 0 Then
Label2.Caption = 0
Label3.Caption = 0
ElseIf a = 0 Then
Label2.Caption = 1
Label3.Caption = c
ElseIf b = 0 Then
Label2.Caption = c
Label3.Caption = 1
Else
' i = -100
' While i <= 100 And Not lb_Trouve
' n = -100
' While n <= 100 And Not lb_Trouve
' If a * i + b * n = c Then
' Label2.Caption = i
' Label3.Caption = n
' lb_Trouve = True
' End If
' n = n + 1
' Wend
' i = i + 1
' Wend
For i = -100 To 100
For n = -100 To 100
If a * i + b * n = c Then
Label2.Caption = i
Label3.Caption = n
Exit For
Exit For
End If
Next n
Next i
End If
End Sub