Dim message As String = "Veuillez saisir des entiers numériques !!!"
Private Sub btncompare_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btncompare.Click 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 MessageBox.Show("Nombre1 > Nombre2 > Nombre3") Else 'Nombre3 > Nombre2 MessageBox.Show("Nombre1 > Nombre3 > Nombre2") End If Else 'Nombre3 > Nombre1 MessageBox.Show("Nombre3 > Nombre1 > Nombre2") End If Else 'Nombre2 > Nombre1 If txtnb1.Text > txtnb3.Text Then 'Nombre1 > Nombre3 MessageBox.Show("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 MessageBox.Show("Nombre2 > Nombre3 > Nombre1") Else 'Nombre3 > Nombre2 MessageBox.Show("Nombre3 > Nombre2 > Nombre1") End If End If End If
If Not IsNumeric(txtnb1.Text) Or Not IsNumeric(txtnb2.Text) Or Not IsNumeric(txtnb3.Text) Then MessageBox.Show("Veuillez saisir des entiers numériques !!!") Exit Sub End If
Dim nb1 As Int32 = Convert.ToInt32(txtnb1.Text) Dim nb2 As Int32 = Convert.ToInt32(txtnb2.Text) Dim nb3 As Int32 = Convert.ToInt32(txtnb3.Text) If nb1 > nb2 Then 'Nombre1 > Nombre2 If nb1 > nb3 Then 'Nombre1 > Nombre3 mais on ne sait pas encore si c'est 1-2-3 ou 1-3-2 If nb2 > nb3 Then ....
Dim nb1 As Int32 Dim nb2 As Int32 Dim nb3 As Int32 If Not Int32.TryParse(txtnb1.Text, nb1) Or Not Int32.TryParse(txtnb2.Text, nb2) Or Not Int32.TryParse(txtnb3.Text, nb3) Then MessageBox.Show("Veuillez saisir des entiers numériques !!!") Exit Sub End If If nb1 > nb2 Then .....
Vous n’avez pas trouvé la réponse que vous recherchez ?
Posez votre questionPrivate 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 Not IsNumeric(txtnb1.Text) Or Not IsNumeric(txtnb2.Text) Or Not IsNumeric(txtnb3.Text) Then MessageBox.Show("Veuillez saisir des entiers numériques !!!") Exit Sub End If 'À partir d'ici on est sûrs que toutes les valeurs sont bien numériques Dim nb1 As Int32 = Convert.ToInt32(txtnb1.Text) Dim nb2 As Int32 = Convert.ToInt32(txtnb2.Text) Dim nb3 As Int32 = Convert.ToInt32(txtnb3.Text) If nb1 > nb2 Then 'Nombre1 > Nombre2 If nb1 > nb3 Then 'Nombre1 > Nombre3 mais on ne sait pas encore si c'est 1-2-3 ou 1-3-2 If nb2 > nb3 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 nb1 > nb3 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 nb2 > nb3 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
Dim nb1 As Int32 = Convert.ToInt32(txtnb1.Text)a quoi sa sert de mettre int32 ?
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 Not IsNumeric(txtnb1.Text) Or Not IsNumeric(txtnb2.Text) Or Not IsNumeric(txtnb3.Text) Then MessageBox.Show("Veuillez saisir des entiers numériques !!!") Exit Sub End If 'À partir d'ici on est sûrs que toutes les valeurs sont bien numériques 'Dim nb1 As Int32 = Convert.ToInt32(txtnb1.Text) 'Dim nb2 As Int32 = Convert.ToInt32(txtnb2.Text) 'Dim nb3 As Int32 = Convert.ToInt32(txtnb3.Text) 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 End Class
If nb1.text > nb2.text AND nb2.text > nb3.text then msgbox("nb1>nb2>nb3") end if If nb3.text > nb1.text AND nb1.text > nb2.text then msgbox("nb3>nb1>nb2") end if If nb2.text > nb1.text AND nb1.text > nb3.text then msgbox("nb2>nb1>nb3") end if If nb3.text > nb2.text AND nb2.text > nb1.text then msgbox("nb3>nb2>nb1") end if If nb1.text > nb3.text AND nb3.text > nb2.text then msgbox("nb1>nb3>nb2") end if If nb2.text > nb3.text AND nb3.text > nb1.text then msgbox("nb2>nb3>nb1") end if
Dim nb1 As String = txtnb1.Text Dim nb2 As String = txtnb2.Text Dim nb3 As String = txtnb3.Text
Dim nb1 As String = txtnb1.Text, cela signifie que l'on "cree" notre langage (ici nb1) qui se réfère a au nom dans la propriété de notre textbox ??
Public Class Form1 Private Function ComparaisonEntier(ByVal X As Integer, ByVal Y As Integer) As Integer Return X.CompareTo(Y) End Function Private Sub btnRanger_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnRanger.Click 'Transfert du contenu des textboxes dans une liste (sans conversion !!!) Dim pliste As New List(Of Integer) Try pliste.Add(TextBox1.Text) pliste.Add(TextBox2.Text) pliste.Add(TextBox3.Text) Catch ex As Exception MessageBox.Show("Les textBoxes doivent contenir des valeurs numériques !") Return End Try 'Tri pliste.Sort(AddressOf ComparaisonEntier) 'Composition d'une chaîne à afficher dans le Labels (j'aurais pu afficher les élements directement mais bon...) Dim chaine As String = "" For Each elt As Integer In pliste chaine &= elt.ToString & "<" Next Label1.Text = chaine.Substring(0, chaine.Length - 1) 'Fini ! End Sub End Class
Public Class Form1 Private Sub Button1_Click(ByVal sender As Object, ByVal e As EventArgs) Handles Button1.Click MessageBox.Show( ( From txt In Controls.OfType(Of TextBox)() Where Integer.TryParse(txt.Text, Nothing) Let value = Integer.Parse(txt.Text) Order By value Descending Select value ).Aggregate(String.Empty, Function(acc, current) If(String.IsNullOrEmpty(acc), current.ToString, acc & " > " & current))) End Sub End Class