Exercice Visual Basic : Les Opérations Arithmétique
Rédigé par GC Team, Publié le 05 Janvier 2012, Mise à jour le Samedi, 17 Décembre 2022 15:56![](/images/thumb/146/default.png)
Participez au vote ☆☆☆☆☆★★★★★
Ecrire le code VB qui permet de réaliser l'interface suivante:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 |
Public Class Form1 Dim TypeOpération As String Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click txtN1.Clear() txtN2.Clear() txtResult.Clear() txtN1.Focus() End Sub Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load RadioButton1.Checked = True TypeOpération = "+" ' Button2.Enabled = False txtN1.TextAlign = HorizontalAlignment.Right txtN2.TextAlign = HorizontalAlignment.Right txtResult.TextAlign = HorizontalAlignment.Right End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click Dim Nbr1, Nbr2 As Double Dim Nbr3 As String = "" Nbr1 = Val(txtN1.Text) Nbr2 = Val(txtN2.Text) Select Case TypeOpération Case "+" Nbr3 = Nbr1 + Nbr2 Case "-" Nbr3 = Nbr1 - Nbr2 Case "*" Nbr3 = Nbr1 * Nbr2 Case "/" Nbr3 = Nbr1 / Nbr2 Case "V" Label2.Text = "V" If txtN1.Text "" Then If txtN2.Text "" Then Nbr3 = Format(Math.Sqrt(Nbr1), "0.0000") Nbr3 &= vbTab & Format(Math.Sqrt(Nbr2), "0.0000") Else Nbr3 = Format(Math.Sqrt(Nbr1), "0.0000") End If Else If txtN2.Text "" Then Nbr3 = Format(Math.Sqrt(Nbr2), "0.0000") End If End If End Select txtResult.Text = Nbr3 End Sub 'Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged ' If TextBox1.Text = "" Then ' Button2.Enabled = False ' Else ' If TextBox2.Text = "" Then ' Button2.Enabled = False ' Else ' Button2.Enabled = True ' End If ' End If 'End Sub 'Private Sub TextBox2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox2.TextChanged ' If TextBox2.Text = "" Then ' Button2.Enabled = False ' Else ' If TextBox1.Text = "" Then ' Button2.Enabled = False ' Else ' Button2.Enabled = True ' End If ' End If 'End Sub Private Sub RadioButton2_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton2.CheckedChanged TypeOpération = "-" Label2.Text = "-" End Sub Private Sub RadioButton3_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton3.CheckedChanged TypeOpération = "*" Label2.Text = "*" End Sub Private Sub RadioButton4_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton4.CheckedChanged TypeOpération = "/" Label2.Text = "/" End Sub Private Sub RadioButton5_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton5.CheckedChanged TypeOpération = "V" Label2.Text = "V" End Sub Private Sub RadioButton1_CheckedChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RadioButton1.CheckedChanged TypeOpération = "+" Label2.Text = "+" End Sub End Class |