Integer Calculator Form

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Corey Dyke

    #1

    Integer Calculator Form

    Hi, I'm doing a lab for my C# course. This is the jist of it:

    Allow the user to enter 2 integer in seperate text boxes, then
    give them the choice of 4 buttons: +, -, * and /
    The answer should display in a seperate textbox upon the user
    clicking one of the 4 buttons.

    I have it all done, I just can't seem to get the answer to display
    in the textbox when I click one of the buttons.

    What am I missing??


    Thanks for any help you can give

    Corey


  • Paul E Collins

    #2
    Re: Integer Calculator Form

    "Corey Dyke" <newfiesrule69@ hotmail.com> wrote:
    [color=blue]
    > [...]
    > I just can't seem to get the answer to display
    > in the textbox when I click one of the buttons.
    > What am I missing??[/color]

    Pretty difficult to guess without seeing any of your code.

    How are you trying to do it?

    P.

    --



    Comment

    • Corey Dyke

      #3
      Re: Integer Calculator Form

      well he didn't want us to use .NET to code it, he wanted it
      coded in notepad and compiled using a csc.bat file that he has setup
      for us to use.

      This is what i have set up to test the integers that are entered:

      void OnClickedAdd (object sender, EventArgs e)
      {
      try
      {
      int display = Int32.Parse(ans .Text);
      display = Convert.ToInt32 (num1.Text) +
      Convert.ToInt32 (num2.Text);
      }
      catch{};
      }

      and i have similar methods for each of the other operators (-,* and /)
      i just have to get it to display the answer. if you need to see more code,
      i can email you my .cs file, or post more here.

      Thanks for any help,

      Corey
      "Paul E Collins" <find_my_real_a ddress@CL4.org> wrote in message
      news:bla56h$bmv $1@sparta.btint ernet.com...[color=blue]
      > "Corey Dyke" <newfiesrule69@ hotmail.com> wrote:
      >[color=green]
      > > [...]
      > > I just can't seem to get the answer to display
      > > in the textbox when I click one of the buttons.
      > > What am I missing??[/color]
      >
      > Pretty difficult to guess without seeing any of your code.
      >
      > How are you trying to do it?
      >
      > P.
      >
      > --
      > www.CL4.org
      >
      >[/color]


      Comment

      • Nicholas Paldino [.NET/C# MVP]

        #4
        Re: Integer Calculator Form

        Corey,

        What I would do is create a single event handler for all four of the
        buttons. Once you have that, you can determine which button was clicked
        based on the sender parameter of your event handler. The text of the button
        should determine the sign to apply to the two operands. Then, once done,
        you can just set the Text property of the third textbox to the result.

        Hope this helps.


        --
        - Nicholas Paldino [.NET/C# MVP]
        - nick(dot)paldin o=at=exisconsul ting<dot>com

        "Corey Dyke" <newfiesrule69@ hotmail.com> wrote in message
        news:%r%db.2602 8$AC3.676098@ne ws2.telusplanet .net...[color=blue]
        > Hi, I'm doing a lab for my C# course. This is the jist of it:
        >
        > Allow the user to enter 2 integer in seperate text boxes, then
        > give them the choice of 4 buttons: +, -, * and /
        > The answer should display in a seperate textbox upon the user
        > clicking one of the 4 buttons.
        >
        > I have it all done, I just can't seem to get the answer to display
        > in the textbox when I click one of the buttons.
        >
        > What am I missing??
        >
        >
        > Thanks for any help you can give
        >
        > Corey
        >
        >[/color]


        Comment

        • Jonathan

          #5
          Re: Integer Calculator Form

          void OnClickedAdd (object sender, EventArgs e)
          {
          try
          {
          int display;
          display = Convert.ToInt32 (num1.Text) +
          Convert.ToInt32 (num2.Text);
          ans.Text = display.ToStrin g();
          }
          catch{};
          }

          and i have
          Corey Dyke wrote:
          [color=blue]
          > Hi, I'm doing a lab for my C# course. This is the jist of it:
          >
          > Allow the user to enter 2 integer in seperate text boxes, then
          > give them the choice of 4 buttons: +, -, * and /
          > The answer should display in a seperate textbox upon the user
          > clicking one of the 4 buttons.
          >
          > I have it all done, I just can't seem to get the answer to display
          > in the textbox when I click one of the buttons.
          >
          > What am I missing??
          >
          >
          > Thanks for any help you can give
          >
          > Corey
          >
          >[/color]

          Comment

          • Corey Dyke

            #6
            Re: Integer Calculator Form

            Awesome.
            Thanks Johnathan

            much appreciated : )

            although i should have noticed that myself
            hehe

            Corey

            "Jonathan" <dataerror.geo@ yahoo.com> wrote in message
            news:uHTM4hvhDH A.1864@TK2MSFTN GP10.phx.gbl...[color=blue]
            > void OnClickedAdd (object sender, EventArgs e)
            > {
            > try
            > {
            > int display;
            > display = Convert.ToInt32 (num1.Text) +
            > Convert.ToInt32 (num2.Text);
            > ans.Text = display.ToStrin g();
            > }
            > catch{};
            > }
            >
            > and i have
            > Corey Dyke wrote:
            >[color=green]
            > > Hi, I'm doing a lab for my C# course. This is the jist of it:
            > >
            > > Allow the user to enter 2 integer in seperate text boxes, then
            > > give them the choice of 4 buttons: +, -, * and /
            > > The answer should display in a seperate textbox upon the user
            > > clicking one of the 4 buttons.
            > >
            > > I have it all done, I just can't seem to get the answer to display
            > > in the textbox when I click one of the buttons.
            > >
            > > What am I missing??
            > >
            > >
            > > Thanks for any help you can give
            > >
            > > Corey
            > >
            > >[/color]
            >[/color]


            Comment

            • Tom

              #7
              Re: Integer Calculator Form

              Hmmm... well, your code doesn't even attempt to set the value of the Text
              property for the ans textbox. Perhaps you meant something like:

              void OnClickAdded(ob ject sender, EventArgs e)
              {
              try
              {
              asn.Text = (Int32.Parse(nu m1.Text) +
              Int32.Parse(num 2.Text)).ToStri ng();
              }
              catch {}
              }

              If you want an A, you might also setup handlers on the num1 and num2
              textboxes for the KeyDown event and set e.Handled = true if the key is not
              one of Key0 throught Key9.

              Tom Clement
              Apptero, Inc.

              "Corey Dyke" <newfiesrule69@ hotmail.com> wrote in message
              news:MR0eb.2405 3$o21.21286@edt nps84...[color=blue]
              > well he didn't want us to use .NET to code it, he wanted it
              > coded in notepad and compiled using a csc.bat file that he has setup
              > for us to use.
              >
              > This is what i have set up to test the integers that are entered:
              >
              > void OnClickedAdd (object sender, EventArgs e)
              > {
              > try
              > {
              > int display = Int32.Parse(ans .Text);
              > display = Convert.ToInt32 (num1.Text) +
              > Convert.ToInt32 (num2.Text);
              > }
              > catch{};
              > }
              >
              > and i have similar methods for each of the other operators (-,* and /)
              > i just have to get it to display the answer. if you need to see more[/color]
              code,[color=blue]
              > i can email you my .cs file, or post more here.
              >
              > Thanks for any help,
              >
              > Corey
              > "Paul E Collins" <find_my_real_a ddress@CL4.org> wrote in message
              > news:bla56h$bmv $1@sparta.btint ernet.com...[color=green]
              > > "Corey Dyke" <newfiesrule69@ hotmail.com> wrote:
              > >[color=darkred]
              > > > [...]
              > > > I just can't seem to get the answer to display
              > > > in the textbox when I click one of the buttons.
              > > > What am I missing??[/color]
              > >
              > > Pretty difficult to guess without seeing any of your code.
              > >
              > > How are you trying to do it?
              > >
              > > P.
              > >
              > > --
              > > www.CL4.org
              > >
              > >[/color]
              >
              >[/color]


              Comment

              Working...