Ecrire le programme qui permet de réaliser l'interface suivante:
Solution
Public Class calculatrice Dim stock, result As Integer Dim op Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles sept.Click sept.Text = "7" TextBox1.Text = TextBox1.Text & sept.Text End Sub Private Sub deux_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles deux.Click deux.Text = "2" TextBox1.Text = TextBox1.Text & deux.Text End Sub Private Sub trois_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles trois.Click trois.Text = "3" TextBox1.Text = TextBox1.Text & trois.Text End Sub Private Sub ktr_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ktr.Click ktr.Text = "4" TextBox1.Text = TextBox1.Text & ktr.Text End Sub Private Sub cinq_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles cinq.Click cinq.Text = "5" TextBox1.Text = TextBox1.Text & cinq.Text End Sub Private Sub six_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles six.Click six.Text = "6" TextBox1.Text = TextBox1.Text & six.Text End Sub Private Sub huit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles huit.Click huit.Text = "8" TextBox1.Text = TextBox1.Text & huit.Text End Sub Private Sub neuf_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles neuf.Click neuf.Text = "9" TextBox1.Text = TextBox1.Text & neuf.Text End Sub Private Sub un_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles un.Click un.Text = "1" TextBox1.Text = TextBox1.Text & un.Text End Sub Private Sub zero_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles zero.Click zero.Text = "0" TextBox1.Text = TextBox1.Text & zero.Text End Sub Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click TextBox1.Text = "" End Sub Private Sub virgul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles virgul.Click virgul.Text = "," TextBox1.Text = TextBox1.Text & virgul.Text End Sub Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click stock = TextBox1.Text TextBox1.Text = "" op = "+" End Sub Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles egal.Click If op = "+" Then TextBox1.Text = Trim(Val(TextBox1.Text)) + stock ElseIf op = "-" Then TextBox1.Text = stock - Trim(Val(TextBox1.Text)) ElseIf op = "*" Then TextBox1.Text = Trim(Val(TextBox1.Text)) * stock ElseIf op = "/" Then TextBox1.Text = stock / Trim(Val(TextBox1.Text)) End If End Sub Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click stock = TextBox1.Text TextBox1.Text = "" op = "-" End Sub Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click stock = TextBox1.Text TextBox1.Text = "" op = "*" End Sub Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click stock = TextBox1.Text TextBox1.Text = "" op = "/" End Sub Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles retourne.Click TextBox1.Text = Mid(TextBox1.Text, 1, (Len(TextBox1.Text) - 1)) TextBox1.Text = Val(TextBox1.Text) End Sub Private Sub moinplus_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles moinplus.Click If Val(TextBox1.Text) < 0 Then TextBox1.Text = Val(TextBox1.Text) * (-1) Else TextBox1.Text = Val(TextBox1.Text) * (-1) End If End Sub Private Sub racine_Click_2(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles racine.Click TextBox1.Text = Math.Sqrt(Val(TextBox1.Text)) End Sub Private Sub por_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles por.Click TextBox1.Text = Val(TextBox1.Text) * 1 / 100 End Sub Private Sub carré_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles carré.Click TextBox1.Text = Val(TextBox1.Text) * Val(TextBox1.Text) End Sub End Class
Aucun commentaire:
Enregistrer un commentaire