Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. C#
  4. Calculator

Calculator

Scheduled Pinned Locked Moved C#
question
15 Posts 6 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • B Offline
    B Offline
    Burim Rama
    wrote on last edited by
    #1

    Hey I have a textbox with values = 1 + 1,3 + 1 + 7 How can i calculate that so when i push the button calculate will give the result = 10,3 Thanks very very mutch its really importing

    L B P N 4 Replies Last reply
    0
    • B Burim Rama

      Hey I have a textbox with values = 1 + 1,3 + 1 + 7 How can i calculate that so when i push the button calculate will give the result = 10,3 Thanks very very mutch its really importing

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      http://www.codeproject.com/KB/recipes/EvaluationEngine.aspx[^]

      1 Reply Last reply
      0
      • B Burim Rama

        Hey I have a textbox with values = 1 + 1,3 + 1 + 7 How can i calculate that so when i push the button calculate will give the result = 10,3 Thanks very very mutch its really importing

        B Offline
        B Offline
        blackjack2150
        wrote on last edited by
        #3

        AFAIK, this things are done by converting the arithmetic expression to it's postfix form. Do some reading on that.

        B 1 Reply Last reply
        0
        • B blackjack2150

          AFAIK, this things are done by converting the arithmetic expression to it's postfix form. Do some reading on that.

          B Offline
          B Offline
          Burim Rama
          wrote on last edited by
          #4

          thaks very mutch but you do not have som method like double.parse(textbox.text) or somthing like that som can help me out of here. I used Inof.Lundin.Math but this cannon add decimal this can just add 1+1 = 2 but not 1+1,4 = 2,4

          B L 2 Replies Last reply
          0
          • B Burim Rama

            thaks very mutch but you do not have som method like double.parse(textbox.text) or somthing like that som can help me out of here. I used Inof.Lundin.Math but this cannon add decimal this can just add 1+1 = 2 but not 1+1,4 = 2,4

            B Offline
            B Offline
            blackjack2150
            wrote on last edited by
            #5

            Just out of curiosity I downloaded the library you mentioned and it works for me. This is my small test:

            info.lundin.Math.ExpressionParser exp = new info.lundin.Math.ExpressionParser();

            Hashtable h = new Hashtable();
            h.Add("x", "1");
            h.Add("y", "1,5");
            h.Add("z", "0,23");

            double result = exp.Parse("x + y + z", h);
            MessageBox.Show(result.ToString());

            The result is 2,73 -just as expected. EDIT: If you want to take the expression directly from a textbox, use this code:

            info.lundin.Math.ExpressionParser exp = new info.lundin.Math.ExpressionParser();

            Hashtable h = new Hashtable();

            double result = exp.Parse(myTextBox.Text, h);
            MessageBox.Show(result.ToString());

            This also works for me. However (just a guess), you might get that error because you are using incorrect decimal separator for your culture. On my machine the comma is the separator, but for you it might be the dot. Check it.

            B 1 Reply Last reply
            0
            • B blackjack2150

              Just out of curiosity I downloaded the library you mentioned and it works for me. This is my small test:

              info.lundin.Math.ExpressionParser exp = new info.lundin.Math.ExpressionParser();

              Hashtable h = new Hashtable();
              h.Add("x", "1");
              h.Add("y", "1,5");
              h.Add("z", "0,23");

              double result = exp.Parse("x + y + z", h);
              MessageBox.Show(result.ToString());

              The result is 2,73 -just as expected. EDIT: If you want to take the expression directly from a textbox, use this code:

              info.lundin.Math.ExpressionParser exp = new info.lundin.Math.ExpressionParser();

              Hashtable h = new Hashtable();

              double result = exp.Parse(myTextBox.Text, h);
              MessageBox.Show(result.ToString());

              This also works for me. However (just a guess), you might get that error because you are using incorrect decimal separator for your culture. On my machine the comma is the separator, but for you it might be the dot. Check it.

              B Offline
              B Offline
              Burim Rama
              wrote on last edited by
              #6

              Thanks very mutch blackjac But it still not work if i use dot ex. 1.4 then it takes it like 14 and if i use 1,4 coms with error "No value associated with 1,4"

              1 Reply Last reply
              0
              • B Burim Rama

                thaks very mutch but you do not have som method like double.parse(textbox.text) or somthing like that som can help me out of here. I used Inof.Lundin.Math but this cannon add decimal this can just add 1+1 = 2 but not 1+1,4 = 2,4

                L Offline
                L Offline
                leppie
                wrote on last edited by
                #7

                2,4 is not a valid decimal/floating-point-number in most cultures.

                xacc.ide - now with TabsToSpaces support
                IronScheme - 1.0 alpha 4a out now (29 May 2008)

                B 1 Reply Last reply
                0
                • L leppie

                  2,4 is not a valid decimal/floating-point-number in most cultures.

                  xacc.ide - now with TabsToSpaces support
                  IronScheme - 1.0 alpha 4a out now (29 May 2008)

                  B Offline
                  B Offline
                  Burim Rama
                  wrote on last edited by
                  #8

                  i use a culture en US ? in my web.aspx project.

                  L P 2 Replies Last reply
                  0
                  • B Burim Rama

                    i use a culture en US ? in my web.aspx project.

                    L Offline
                    L Offline
                    leppie
                    wrote on last edited by
                    #9

                    Then you need a dot '.' not a comma ',' eg 2.453

                    xacc.ide - now with TabsToSpaces support
                    IronScheme - 1.0 alpha 4a out now (29 May 2008)

                    B 1 Reply Last reply
                    0
                    • L leppie

                      Then you need a dot '.' not a comma ',' eg 2.453

                      xacc.ide - now with TabsToSpaces support
                      IronScheme - 1.0 alpha 4a out now (29 May 2008)

                      B Offline
                      B Offline
                      Burim Rama
                      wrote on last edited by
                      #10

                      Now it works.. thank thanks very much..

                      L 1 Reply Last reply
                      0
                      • B Burim Rama

                        Now it works.. thank thanks very much..

                        L Offline
                        L Offline
                        leppie
                        wrote on last edited by
                        #11

                        Burim Rama wrote:

                        thank thanks very much..

                        No problem, was easy once I had all the info :)

                        xacc.ide - now with TabsToSpaces support
                        IronScheme - 1.0 alpha 4a out now (29 May 2008)

                        B 1 Reply Last reply
                        0
                        • L leppie

                          Burim Rama wrote:

                          thank thanks very much..

                          No problem, was easy once I had all the info :)

                          xacc.ide - now with TabsToSpaces support
                          IronScheme - 1.0 alpha 4a out now (29 May 2008)

                          B Offline
                          B Offline
                          Burim Rama
                          wrote on last edited by
                          #12

                          somtimes you can use lot of time with som easy code

                          1 Reply Last reply
                          0
                          • B Burim Rama

                            Hey I have a textbox with values = 1 + 1,3 + 1 + 7 How can i calculate that so when i push the button calculate will give the result = 10,3 Thanks very very mutch its really importing

                            P Offline
                            P Offline
                            Paul Conrad
                            wrote on last edited by
                            #13

                            Burim Rama wrote:

                            its really importing

                            :laugh::laugh::laugh: You mean important :rolleyes:

                            "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                            1 Reply Last reply
                            0
                            • B Burim Rama

                              i use a culture en US ? in my web.aspx project.

                              P Offline
                              P Offline
                              Paul Conrad
                              wrote on last edited by
                              #14

                              Burim Rama wrote:

                              i use a culture en US ?

                              Decimals are not done with commas in the US :suss:

                              "The clue train passed his station without stopping." - John Simmons / outlaw programmer "Real programmers just throw a bunch of 1s and 0s at the computer to see what sticks" - Pete O'Hanlon "Not only do you continue to babble nonsense, you can't even correctly remember the nonsense you babbled just minutes ago." - Rob Graham

                              1 Reply Last reply
                              0
                              • B Burim Rama

                                Hey I have a textbox with values = 1 + 1,3 + 1 + 7 How can i calculate that so when i push the button calculate will give the result = 10,3 Thanks very very mutch its really importing

                                N Offline
                                N Offline
                                nelsonpaixao
                                wrote on last edited by
                                #15

                                do you want to put all together on the screen? 1 + 1,3 + 1 + 7 if not add a button "=" use: int total; click button "=" event (or other) inside put: total = total + convert.toint32(textbox_x)

                                nelsonpaixao@yahoo.com.br trying to help & get help

                                1 Reply Last reply
                                0
                                Reply
                                • Reply as topic
                                Log in to reply
                                • Oldest to Newest
                                • Newest to Oldest
                                • Most Votes


                                • Login

                                • Don't have an account? Register

                                • Login or register to search.
                                • First post
                                  Last post
                                0
                                • Categories
                                • Recent
                                • Tags
                                • Popular
                                • World
                                • Users
                                • Groups