Private Sub btncompare_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btncompare.Click Dim numbers(2) As Integer Dim message As String = "Only integer values please !" If Integer.TryParse(txtnb1.Text, numbers(0)) AndAlso Integer.TryParse(txtnb2.Text, numbers(1)) AndAlso Integer.TryParse(txtnb3.Text, numbers(2)) Then Array.Sort(numbers) message = numbers(0).ToString For i As Integer = 1 To numbers.Count - 1 message &= " <= " & numbers(i) Next End If MessageBox.Show(message) End Sub
Private Sub btncompare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncompare.Click If IsNumeric(txtnb1.Text) And IsNumeric(txtnb2.Text) And IsNumeric(txtnb3.Text) Then '' Toutes les valeurs sont numériques Dim s As String = "" '' Déclare s For i = 0 To 5000 '' Faire une boucle de 0 à 5000 If CInt(txtnb1.Text) = i Then s &= "Nombre 1 (" & i & ") <= " '' Si un est égal à i If CInt(txtnb2.Text) = i Then s &= "Nombre 2 (" & i & ") <= " ' Nombre 2 (i) <= If CInt(txtnb3.Text) = i Then s &= "Nombre 3 (" & i & ") <= " ' Nombre 3 (i) <= Next Dim resultat As String = s.Substring(0, Len(s) - 4) ' Enlève les 4 derniers caractères MessageBox.Show(resultat) Else '' Une valeur n'est pas numérique MessageBox.Show("Veuillez entrer des valeurs numériques uniquement") Exit Sub ''Quitte la Sub End If End Sub
If nb2 > nb3 Then '--> true
If Val(nb1.Text) > Val(nb2.Text) And Val(nb2.Text) > Val(nb3.Text) Then MsgBox("nb1>nb2>nb3") End If If Val(nb3.Text) > Val(nb1.Text) And Val(nb1.Text) > Val(nb2.Text) Then MsgBox("nb3>nb1>nb2") End If If Val(nb2.Text) > Val(nb1.Text) And Val(nb1.Text) > Val(nb3.Text) Then MsgBox("nb2>nb1>nb3") End If If Val(nb3.Text) > Val(nb2.Text) And Val(nb2.Text) > Val(nb1.Text) Then MsgBox("nb3>nb2>nb1") End If If Val(nb1.Text) > Val(nb3.Text) And Val(nb3.Text) > Val(nb2.Text) Then MsgBox("nb1>nb3>nb2") End If If Val(nb2.Text) > Val(nb3.Text) And Val(nb3.Text) > Val(nb1.Text) Then MsgBox("nb2>nb3>nb1") End If Exit Sub
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate Sub btncompare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncompare.Click If IsNumeric(txtnb1.Text) or IsNumeric(txtnb2.Text) or IsNumeric(txtnb3.Text) Then MessageBox.Show("Veuillez saisir des entiers numériques !!!") exit sub end if If txtnb1.Text > txtnb2.Text and txtnb2.Text > txtnb3.Text Then MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Exit Sub end if If txtnb2.Text > txtnb3.Text and txtnb3.Text > txtnb1.Text Then MessageBox.Show("Nombre2 > Nombre 3 > Nombre1") Exit Sub end if If txtnb2.Text > txtnb1.Text and txtnb1.Text > txtnb3.Text Then MessageBox.Show("Nombre2 > Nombre1 > Nombre3") Exit Sub End If If txtnb3.Text > txtnb1.Text and txtnb1.Text > txtnb2.Text Then MessageBox.Show("Nombre3 > Nombre1 > Nombre2") Exit Sub end if If txtnb1.Text > txtnb2.Text and txtnb2.Text > txtnb3.Text Then MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Exit Sub end if End Sub
Sub algo3(ByVal un As Integer, ByVal deux As Integer, ByVal trois As Integer) Dim t(2) As Integer t(0) = un t(1) = deux t(2) = trois Dim resultat(2) As String Dim s As String = "" For i = 0 To 5000 If un = i Then s &= "Nombre 1 = " & i & " " If trois = i Then s &= "Nombre 3 = " & i & " " If deux = i Then s &= "Nombre 2 = " & i & " " Next MessageBox.Show(s) End Sub
algo3(txtnb1.Text,txtnb2.Text,txtnb2.Text)
Sub algo3(ByVal un As Integer, ByVal deux As Integer, ByVal trois As Integer) Dim t(2) As Integer '' Déclare un tableau t de longeur 3 (base 0) t(0) = un '' met les éléments envoyés à la Sub algo3 t(1) = deux t(2) = trois '' Dans le tableau t Dim s As String = "" '' Déclare s For i = 0 To 5000 '' Faire une boucle de 0 à 5000 If un = i Then s &= "Nombre 1 ( " & i & "<= " '' Si un est égal à i '' ajoute à la chaine de caratères s : Nombre 1 (i) <If deux i Then s &= "Nombre 2 ( " & i & "<= " ' Nombre 2 (i) <= If trois = i Then s &= "Nombre 3 ( " & i & "<= " ' Nombre 3 (i) <= Next Dim resultat As String = s.Substring(0, Len(s) - 4) '' Enlève les 4 derniers caratères '' dans s car comme on ne connait pas l'ordre '' il y a un <= à la fin MessageBox.Show(resultat) End Sub
Private Sub btncompare_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncompare.Click If IsNumeric(txtnb1.Text) Then If IsNumeric(txtnb2.Text) Then If IsNumeric(txtnb3.Text) Then If txtnb1.Text > txtnb2.Text Then If txtnb2.Text > txtnb3.Text Then MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Exit Sub If txtnb1.Text > txtnb3.Text Then MessageBox.Show("Nombre2 > Nombre 3 > Nombre1") Exit Sub Else : MessageBox.Show("Nombre2 > Nombre1 > Nombre3") Exit Sub End If End If If txtnb1.Text > txtnb3.Text Then MessageBox.Show("Nombre3 > Nombre1 > Nombre2") Exit Sub If txtnb3.Text > txtnb2.Text Then MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Exit Sub Else : MessageBox.Show("Nombre1 > Nombre2 > Nombre3") End If End If End If Else : MessageBox.Show("Veuillez saisir des entiers numériques !!!") End If Else : MessageBox.Show("Veuillez saisir des entiers numériques !!!") End If Else : MessageBox.Show("Veuillez saisir des entiers numériques !!!") End If End Sub
If txtnb1.Text > txtnb2.Text Then ' Ici on peut déjà dire Nombre1 > Nombre2 If txtnb2.Text > txtnb3.Text Then MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Exit Sub ' Cette partie du code ne sera jamais atteinte à cause du Exit Sub juste avant ' Je mets donc cette partie en commentaire 'If txtnb1.Text > txtnb3.Text Then ' MessageBox.Show("Nombre2 > Nombre 3 > Nombre1") ' Exit Sub 'Else : MessageBox.Show("Nombre2 > Nombre1 > Nombre3") ' Exit Sub 'End If End If If txtnb1.Text > txtnb3.Text Then ' Ici on peut dire que Nombre1 > Nombre3 ' Mais on ne sait pas si Nombre2 > Nombre3 ou le contraire MessageBox.Show("Nombre3 > Nombre1 > Nombre2") Exit Sub ' Comme précédemment cette partie ne sera jamais atteinte ' je commente donc la zone 'If txtnb3.Text > txtnb2.Text Then ' MessageBox.Show("Nombre1 > Nombre2 > Nombre3") ' Exit Sub 'Else : MessageBox.Show("Nombre1 > Nombre2 > Nombre3") 'End If End If End If 'Ici je remets le code sans les commentaires If txtnb1.Text > txtnb2.Text Then If txtnb2.Text > txtnb3.Text Then MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Exit Sub End If If txtnb1.Text > txtnb3.Text Then MessageBox.Show("Nombre3 > Nombre1 > Nombre2") Exit Sub End If End If
If True Then DoSomething() Else : SomethingElse() End If 'ou If True Then DoSomething() Else ' plus besoin des : ici SomethingElse() End If ' de même on peut écrire (même si c'est peu lisible et non recommandé) Dim i As Integer : Dim s As String : i 42 : s "Une Chaine " : MessageBox.Show(s & i.ToString())
Private Sub btncompare_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btncompare.Click Dim message As String = "Veuillez saisir des entiers numériques !!!" If IsNumeric(txtnb1.Text) Then MessageBox.Show(message) Exit Sub End If If IsNumeric(txtnb2.Text) Then MessageBox.Show(message) Exit Sub End If If IsNumeric(txtnb3.Text) Then MessageBox.Show(message) Exit Sub End If 'À partir d'ici on est sûrs que toutes les valeurs sont bien numériques If txtnb1.Text > txtnb2.Text Then 'Nombre1 > Nombre2 If txtnb1.Text > txtnb3.Text Then 'Nombre1 > Nombre3 mais on ne sait pas encore si c'est 1-2-3 ou 1-3-2 If txtnb2.Text > txtnb3.Text Then 'Nombre2 > Nombre3 message = "Nombre1 > Nombre2 > Nombre3" Else 'Nombre3 > Nombre2 message = "Nombre1 > Nombre3 > Nombre2" End If Else 'Nombre3 > Nombre1 message = "Nombre3 > Nombre1 > Nombre2" End If Else 'Nombre2 > Nombre1 If txtnb1.Text > txtnb3.Text Then 'Nombre1 > Nombre3 message = "Nombre2 > Nombre1 > Nombre3 Else 'Nombre3 > Nombre1 mais on ne sait toujours si c'est 2-3-1 ou 3-2-1 If txtnb2.Text > txtnb3.Text Then 'Nombre2 > Nombre3 message = "Nombre2 > Nombre3 > Nombre1" Else 'Nombre3 > Nombre2 message = "Nombre3 > Nombre2 > Nombre1" End If End If End If MessageBox.Show(message) End Sub
If txtnb1.Text > txtnb2.Text Then '' Ici tu vérifie si Nombre1 > Nombre2 '' Donc le code ci dssous ne s'execute que si cette condition est vraie If txtnb2.Text > txtnb3.Text Then MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Exit Sub If txtnb1.Text > txtnb3.Text Then MessageBox.Show("Nombre2 > Nombre 3 > Nombre1") Exit Sub Else MessageBox.Show("Nombre2 > Nombre1 > Nombre3") Exit Sub End If End If If txtnb1.Text > txtnb3.Text Then MessageBox.Show("Nombre3 > Nombre1 > Nombre2") Exit Sub If txtnb3.Text > txtnb2.Text Then MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Exit Sub Else MessageBox.Show("Nombre1 > Nombre2 > Nombre3") End If End If End If '' C'est sur cette ligne que tu arrives si Nombre1 < Nombre2 '' Donc dans ce cas, pas de MessageBox, rien ne se passeras.
If txtnb1.Text > txtnb2.Text and txtnb2.Text > txtnb3.Text Then MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Exit Sub end if If txtnb2.Text > txtnb3.Text and txtnb3.Text > txtnb1.Text Then MessageBox.Show("Nombre2 > Nombre 3 > Nombre1") Exit Sub end if If txtnb2.Text > txtnb1.Text and txtnb1.Text > txtnb3.Text Then MessageBox.Show("Nombre2 > Nombre1 > Nombre3") Exit Sub End If If txtnb3.Text > txtnb1.Text and txtnb1.Text > txtnb2.Text Then MessageBox.Show("Nombre3 > Nombre1 > Nombre2") Exit Sub end if If txtnb1.Text > txtnb2.Text and txtnb2.Text > txtnb3.Text Then MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Exit Sub end if
If IsNumeric(txtnb1.Text) Then If IsNumeric(txtnb2.Text) Then If IsNumeric(txtnb3.Text) Then If txtnb1.Text > txtnb2.Text Then '' Ce premier If If txtnb2.Text > txtnb3.Text Then MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Exit Sub If txtnb1.Text > txtnb3.Text Then MessageBox.Show("Nombre2 > Nombre 3 > Nombre1") Exit Sub Else : MessageBox.Show("Nombre2 > Nombre1 > Nombre3") Exit Sub End If End If If txtnb1.Text > txtnb3.Text Then MessageBox.Show("Nombre3 > Nombre1 > Nombre2") Exit Sub If txtnb3.Text > txtnb2.Text Then MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Exit Sub Else : MessageBox.Show("Nombre1 > Nombre2 > Nombre3") End If End If End If '' renvoie ICI Else : MessageBox.Show("Veuillez saisir des entiers numériques !!!") End If Else : MessageBox.Show("Veuillez saisir des entiers numériques !!!") End If