SoS calculatrice en vb.net 10

redbis Messages postés 2 Date d'inscription dimanche 14 décembre 2014 Statut Membre Dernière intervention 14 décembre 2014 - Modifié par Whismeril le 15/12/2014 à 14:19
Whismeril Messages postés 19028 Date d'inscription mardi 11 mars 2003 Statut Non membre Dernière intervention 24 avril 2024 - 15 déc. 2014 à 14:20
SOS svp j'ai un problem je veux que ma calculette peut calculer des fonctions comme 20.5*6/7+1=
svp je veux savoir la méthode et merci davace
voici mon code

Public Class Form1
    Dim n1, n2 As Double
    Dim result As Double
    Dim virg As Boolean
    Dim st As String




    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        TextBox1.Text = TextBox1.Text + "1"
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        TextBox1.Text = TextBox1.Text + "0"
    End Sub

    Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button6.Click
        TextBox1.Text = TextBox1.Text + "2"
    End Sub

    Private Sub Button10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button10.Click
        TextBox1.Text = TextBox1.Text + "3"
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        TextBox1.Text = TextBox1.Text + "4"
    End Sub

    Private Sub Button7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button7.Click
        TextBox1.Text = TextBox1.Text + "5"
    End Sub

    Private Sub Button11_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button11.Click
        TextBox1.Text = TextBox1.Text + "6"
    End Sub

    Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        TextBox1.Text = TextBox1.Text + "7"
    End Sub

    Private Sub Button8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button8.Click
        TextBox1.Text = TextBox1.Text + "8"
    End Sub

    Private Sub Button12_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button12.Click
        TextBox1.Text = TextBox1.Text + "9"
    End Sub

    Private Sub Button9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button9.Click
        If TextBox1.Text = "" Then
            TextBox1.Text = "0."
        Else
            If virg = False Then
                TextBox1.Text = TextBox1.Text + "."
            End If
            virg = True
        End If
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        TextBox1.Clear()
        TextBox1.Text = "0"
        virg = False
    End Sub

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        TextBox1.Hide()


    End Sub

    Private Sub Button18_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button18.Click
        TextBox1.Show()
        TextBox1.Clear()
        TextBox1.Text = "0"




    End Sub

    Private Sub Button17_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button17.Click
        End

    End Sub

    Private Sub Button16_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button16.Click
        If st = "+" Then
            result = n1 + n2
        End If
        If st = "-" Then
            result = n1 - n2
        End If
        If st = "*" Then
            result = n1 * n2
        End If
        If st = "/" Then
            result = n1 / n2
        End If
        result = n2
        n1 = Val(TextBox1.Text)
        st = "+"
        TextBox1.Clear()
        virg = False

    End Sub

    Private Sub Button15_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button15.Click
        If st = "+" Then
            result = n1 + n2
        End If
        If st = "-" Then
            result = n1 - n2
        End If
        If st = "*" Then
            result = n1 * n2
        End If
        If st = "/" Then
            result = n1 / n2
        End If
        result = n2
        n1 = Val(TextBox1.Text)
        st = "*"
        TextBox1.Clear()
        virg = False
    End Sub

    Private Sub Button14_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button14.Click
        n1 = Val(TextBox1.Text)
        If st = "+" Then
            result = n1 + n2
        End If
        If st = "-" Then
            result = n1 - n2
        End If
        If st = "*" Then
            result = n1 * n2
        End If
        If st = "/" Then
            result = n1 / n2
        End If
        result = n2
        st = "-"
        TextBox1.Clear()
        virg = False
    End Sub

    Private Sub Button13_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button13.Click
        If st = "+" Then
            result = n1 + n2
        End If
        If st = "-" Then
            result = n1 - n2
        End If
        If st = "*" Then
            result = n1 * n2
        End If
        If st = "/" Then
            result = n1 / n2
        End If
        result = n2
        n1 = Val(TextBox1.Text)
        st = "/"
        TextBox1.Clear()
        virg = False
    End Sub

    Private Sub Button20_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button20.Click
        n2 = Val(TextBox1.Text)
        If st = "+" Then
            TextBox1.Text = n1 + n2
        End If
        If st = "-" Then
            TextBox1.Text = n1 - n2
        End If
        If st = "*" Then
            TextBox1.Text = n1 * n2
        End If
        If st = "/" Then
            TextBox1.Text = n1 / n2
        End If

        virg = False
    End Sub

    Private Sub TextBox1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TextBox1.TextChanged

    End Sub
End Class

EDIT: Ajout de la coloration syntaxique.

3 réponses

Bonjour,

Déjà simplifier le code

Cette fonction concentre les events [ click ] de chaques buttons en ajoutant le dernier caractere de la propriétée Text de chaque Button

    Private Sub BOUTON_Click(sender As Object, e As EventArgs) Handles Button1.Click, Button2.Click, Button3.Click   .... 
        Dim F As String = sender.text
        TextBox1.Text = TextBox1.Text & Mid(F, F.Length, 1)
    End Sub
1
Whismeril Messages postés 19028 Date d'inscription mardi 11 mars 2003 Statut Non membre Dernière intervention 24 avril 2024 656
15 déc. 2014 à 14:20
Pense aussi à dire Bonjour
1
cs_ShayW Messages postés 3253 Date d'inscription jeudi 26 novembre 2009 Statut Membre Dernière intervention 3 décembre 2019 57
14 déc. 2014 à 18:00
0
redbis Messages postés 2 Date d'inscription dimanche 14 décembre 2014 Statut Membre Dernière intervention 14 décembre 2014
14 déc. 2014 à 18:19
pardon pour la mauvaise présentation
0
ucfoutu Messages postés 18038 Date d'inscription lundi 7 décembre 2009 Statut Modérateur Dernière intervention 11 avril 2018 211 > redbis Messages postés 2 Date d'inscription dimanche 14 décembre 2014 Statut Membre Dernière intervention 14 décembre 2014
14 déc. 2014 à 18:42
Bonjour,
Hé bien corrige donc.
0
Rejoignez-nous