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
  1. Home
  2. General Programming
  3. WPF
  4. Help with textbox for calculator

Help with textbox for calculator

Scheduled Pinned Locked Moved WPF
questioncsharpwpfhelp
6 Posts 3 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.
  • S Offline
    S Offline
    Sonar87
    wrote on last edited by
    #1

    I'm relatively new to C# and have just started playing around with WPF. As a start I decided to make a simple calculator. I added one of the permade textboxes to take input from the user, but you can't perform addition, subbtraction, and so on, oporations on a string, and it won't let me typecast the string to another type like double. How can I change the textbox input to something I can use, or what is there some other object I can use to get the input?

    N 1 Reply Last reply
    0
    • S Sonar87

      I'm relatively new to C# and have just started playing around with WPF. As a start I decided to make a simple calculator. I added one of the permade textboxes to take input from the user, but you can't perform addition, subbtraction, and so on, oporations on a string, and it won't let me typecast the string to another type like double. How can I change the textbox input to something I can use, or what is there some other object I can use to get the input?

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      You can't cast a string to a number but you can convert it. Any of these will work

      string num = "1";

      int.Parse(num);

      int numOut = 0;
      int.TryParse(num, out numOut);

      Convert.ToInt32(num);


      I know the language. I've read a book. - _Madmatt

      S 1 Reply Last reply
      0
      • N Not Active

        You can't cast a string to a number but you can convert it. Any of these will work

        string num = "1";

        int.Parse(num);

        int numOut = 0;
        int.TryParse(num, out numOut);

        Convert.ToInt32(num);


        I know the language. I've read a book. - _Madmatt

        S Offline
        S Offline
        Sonar87
        wrote on last edited by
        #3

        Even with each of those lines it still tells me it can't convert from string to int. in case its signifigant, I'm using Visual Studio 2008 btw.

        N 1 Reply Last reply
        0
        • S Sonar87

          Even with each of those lines it still tells me it can't convert from string to int. in case its signifigant, I'm using Visual Studio 2008 btw.

          N Offline
          N Offline
          Not Active
          wrote on last edited by
          #4

          You are quite obviously doing something incorrectly, each of those lines is accurate. Post what you are doing? and please don't forget to format it properly, i.e. use pre tags


          I know the language. I've read a book. - _Madmatt

          S 1 Reply Last reply
          0
          • N Not Active

            You are quite obviously doing something incorrectly, each of those lines is accurate. Post what you are doing? and please don't forget to format it properly, i.e. use pre tags


            I know the language. I've read a book. - _Madmatt

            S Offline
            S Offline
            Sonar87
            wrote on last edited by
            #5

            Sorry to take more of your time. I've figured out what I did wrong and have gotten it working now.

            G 1 Reply Last reply
            0
            • S Sonar87

              Sorry to take more of your time. I've figured out what I did wrong and have gotten it working now.

              G Offline
              G Offline
              guyet05
              wrote on last edited by
              #6

              Can you please share code?

              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