Parenthese en vb.net(calculatrice)

bouchrot Messages postés 394 Statut Membre -  
bouchrot Messages postés 394 Statut Membre -
Bonjour,

salut j'ai créer une calculatrice scientifique en vb 2008 contenant le cos, sin, tan, sqrt
mais je n'arrive pas a mettre les parenthèse
s'il vous plait si quelqu'un a une idées merci de me dire comment les faire

5 réponses

  1. ayoami Messages postés 11 Statut Membre 1
     
    Tu peux nous donner ton code bien comprendre le probleme ?
    1
    1. bouchrot Messages postés 394 Statut Membre 6
       
      voila mon code


      Public Class btn0
      Dim nbr1, nbr2 As Single
      Dim Operation As String


      Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn2.Click
      If txtaffiche.Text = "0" Then
      txtaffiche.Text = "2"
      Else
      txtaffiche.Text = txtaffiche.Text & "2"
      End If
      End Sub

      Private Sub btnegal_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnegal.Click
      nbr2 = CSng(txtaffiche.Text)
      Select Case Operation
      Case "+"
      txtaffiche.Text = nbr1 + nbr2
      Case "-"
      txtaffiche.Text = nbr1 - nbr2
      Case "*"
      txtaffiche.Text = nbr1 * nbr2
      Case "/"
      txtaffiche.Text = nbr1 / nbr2
      Case "puissance"
      txtaffiche.Text = nbr1 ^ nbr2

      End Select

      End Sub

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

      End Sub

      Private Sub btnmultiplication_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnmultiplication.Click
      Operation = "*"
      nbr1 = CSng(txtaffiche.Text)
      txtaffiche.Text = 0
      End Sub

      Private Sub btnul_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnul.Click

      If txtaffiche.Text = "0" Then
      txtaffiche.Text = "0"
      Else
      txtaffiche.Text = txtaffiche.Text & "0"
      End If
      End Sub

      Private Sub btn1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn1.Click

      If txtaffiche.Text = "0" Then
      txtaffiche.Text = "1"
      Else
      txtaffiche.Text = txtaffiche.Text & "1"
      End If
      End Sub

      Private Sub btn3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn3.Click
      If txtaffiche.Text = "0" Then
      txtaffiche.Text = "3"
      Else
      txtaffiche.Text = txtaffiche.Text & "3"
      End If
      End Sub

      Private Sub btn4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn4.Click
      If txtaffiche.Text = "0" Then
      txtaffiche.Text = "4"
      Else
      txtaffiche.Text = txtaffiche.Text & "4"
      End If
      End Sub

      Private Sub btn5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn5.Click
      If txtaffiche.Text = "0" Then
      txtaffiche.Text = "5"
      Else
      txtaffiche.Text = txtaffiche.Text & "5"
      End If
      End Sub

      Private Sub btn6_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn6.Click
      If txtaffiche.Text = "0" Then
      txtaffiche.Text = "6"
      Else
      txtaffiche.Text = txtaffiche.Text & "6"
      End If
      End Sub

      Private Sub btn7_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn7.Click
      If txtaffiche.Text = "0" Then
      txtaffiche.Text = "7"
      Else
      txtaffiche.Text = txtaffiche.Text & "7"
      End If
      End Sub

      Private Sub btn8_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn8.Click
      If txtaffiche.Text = "0" Then
      txtaffiche.Text = "8"
      Else
      txtaffiche.Text = txtaffiche.Text & "8"
      End If
      End Sub

      Private Sub btn9_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn9.Click
      If txtaffiche.Text = "0" Then
      txtaffiche.Text = "9"
      Else
      txtaffiche.Text = txtaffiche.Text & "9"
      End If
      End Sub

      Private Sub btnquitter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnquitter.Click
      Dim x As Integer
      x = MsgBox("voulez vous quitter ?", vbYesNo + vbQuestion)

      If x = vbYes Then
      End
      End If

      End Sub

      Private Sub btnclear_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnclear.Click
      txtaffiche.Text = 0
      End Sub

      Private Sub btnC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnC.Click
      txtaffiche.Text = Len(txtaffiche.Text) - 1
      End Sub

      Private Sub btnvirgule_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnvirgule.Click

      If InStr(txtaffiche.Text, ",") = 0 Then
      txtaffiche.Text = txtaffiche.Text & ","
      End If

      End Sub

      Private Sub btnaddition_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnaddition.Click
      Operation = "+"
      nbr1 = CSng(txtaffiche.Text)
      txtaffiche.Text = 0
      End Sub

      Private Sub btnsoustraction_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsoustraction.Click
      Operation = "-"
      nbr1 = CSng(txtaffiche.Text)
      txtaffiche.Text = 0
      End Sub

      Private Sub btndivision_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btndivision.Click
      Operation = "/"
      nbr1 = CSng(txtaffiche.Text)
      txtaffiche.Text = 0
      End Sub

      Private Sub btnneg_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnneg.Click

      If txtaffiche.Text > 0 Then
      txtaffiche.Text = txtaffiche.Text * (-1)
      Else
      txtaffiche.Text = txtaffiche.Text * 1
      End If

      End Sub

      Private Sub btncos_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btncos.Click
      Operation = "cos"
      nbr1 = CSng(txtaffiche.Text)
      txtaffiche.Text = Math.Cos(nbr1)
      End Sub

      Private Sub btnsin_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsin.Click
      Operation = "sin"
      nbr1 = CSng(txtaffiche.Text)
      txtaffiche.Text = Math.Cos(nbr1)
      End Sub

      Private Sub btntan_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btntan.Click
      Operation = "tan"
      nbr1 = CSng(txtaffiche.Text)
      txtaffiche.Text = Math.Cos(nbr1)
      End Sub

      Private Sub btnpuissance_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnpuissance.Click
      Operation = "puissance"
      nbr1 = CSng(txtaffiche.Text)
      txtaffiche.Text = 0
      End Sub

      Private Sub btnù_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnù.Click
      Operation = "%"
      nbr1 = CSng(txtaffiche.Text)
      txtaffiche.Text = txtaffiche.Text / 100
      End Sub

      Private Sub btnx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnx.Click
      Operation = "x"
      nbr1 = CSng(txtaffiche.Text)
      txtaffiche.Text = 1 / nbr1
      End Sub

      Private Sub btnsqrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsqrt.Click
      Operation = "sqrt"
      nbr1 = CSng(txtaffiche.Text)
      txtaffiche.Text = (Math.Sqrt(nbr1))
      End Sub

      Private Sub btn10_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn10.Click
      Operation = "Puis"
      nbr1 = CSng(txtaffiche.Text)
      txtaffiche.Text = 10 ^ txtaffiche.Text
      End Sub

      Private Sub fact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles fact.Click
      Operation = "fact"
      nbr1 = CSng(txtaffiche.Text)
      If nbr1 < 0 Then
      txtaffiche.Text = "erreur"
      Else
      Dim i As Integer
      For i = 1 To nbr1
      nbr1 = nbr1 * i
      Next i
      End If
      End Sub
      End Class
      0
  2. lermite222 Messages postés 9042 Statut Contributeur 1 199
     
    Bonjour,
    Ça dépend comment tu stocke les données
    Tu dis.
    A+
    0
  3. bouchrot Messages postés 394 Statut Membre 6
     
    je vais vous donnez quelque syntaxe de quelque fonctions
    Private Sub btnù_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnù.Click
    Operation = "%"
    nbr1 = CSng(txtaffiche.Text)
    txtaffiche.Text = txtaffiche.Text / 100
    End Sub

    Private Sub btnx_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnx.Click
    Operation = "x"
    nbr1 = CSng(txtaffiche.Text)
    txtaffiche.Text = 1 / nbr1
    End Sub

    Private Sub btnsqrt_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnsqrt.Click
    Operation = "sqrt"
    nbr1 = CSng(txtaffiche.Text)
    0
  4. lermite222 Messages postés 9042 Statut Contributeur 1 199
     
    En faisant une évaluation directe comme tu le fais avec tes boutons ce sera difficile avec des parenthèses.
    J'ai aussi fait une calculatrice, elle n'est pas scientifique mais permet toutes les formules (parenthèses) que l'ont veux.
    Je mémorise chaque frappe dans un string, genre ((125 * 12)+15)/125 et quand ont tape la touche égale je l'envoi dans une routine pour évaluation.
    Ça permet les deux façons, une directe 2+2 par exemple et (2+2)*5
    Tu pourrais aussi combiner les deux en gardant les formules dans tes boutons et en mémorisant le résultat.
    Exemple avec touches appuyées..Affichage ... Variable
    ( .. ( .. (
    ( .. ( .. ((
    2 ..2 .. ((2
    * ..* .. ((2*
    4.. 8 .. ((8
    ) .. ) .. (8
    et ainsi de suite
    Mais moi je préfère saisir tout d'une fois, cela permet à l'utilisateur de rajouter des parenthèses, d'en supprimer ou de corriger facilement sa formule.
    A+
    Si tu te cognes à un pot et que ça sonne creux, c'est pas forcément le pot qui est vide. ;-)(Confucius)
    NOTE : Je ne répond pas aux MP pour les questions techniques.
    0
    1. bouchrot Messages postés 394 Statut Membre 6
       
      si tu as déjà fait les parenthèses donne pas syntaxes s'il te plait
      0
    2. lermite222 Messages postés 9042 Statut Contributeur 1 199
       
      1°) Ce n'est pas en VB.Net
      2°) Je ne vais quand même par te faire ton appli !!, je pense avoir été suffisamment clair dans mon explication, à toi de coder maintenant.
      0
    3. bouchrot Messages postés 394 Statut Membre 6
       
      désolé j'ai pas compris
      0
    4. lermite222 Messages postés 9042 Statut Contributeur 1 199
       
      Un exemple mais uniquement pour l'affichage le code étant en VBA. Et je n'ai pas dû faire la routine d'évaluation, une dll de VBA le fait mais ça ne m'aurais pas poser de problème pour la créer.
      En bref, je laisse l'utilisateur remplir la ligne de texte avec sa formule sans rien faire, ce n'est que quand il appuie sur = que j'évalue.
      0
    5. bouchrot Messages postés 394 Statut Membre 6
       
      en tous cas je vais essayez je ne vais pas croisé les mains et merci pour tout
      0
  5. Vous n’avez pas trouvé la réponse que vous recherchez ?

    Posez votre question
  6. lermite222 Messages postés 9042 Statut Contributeur 1 199
     
    Comme dis, La démo
    A+
    0