Exercice Visual Basic : Les Opérations Arithmétique

Ecrire le code VB qui permet de réaliser l'interface suivante:



123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100Public 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 SubEnd Class
Article publié le 05 Janvier 2012 Mise à jour le Samedi, 17 Décembre 2022 15:56 par GC Team