4 Replies - 705 Views - Last Post: 10 October 2012 - 04:30 AM Rate Topic: -----

#1 risky14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 12-September 12

Subtraction not working on form 3

Posted 09 October 2012 - 03:43 AM

Hello again

I'm using this method for subtracting a stored number from a number the user inputs into the textbox and it's working on form 2 yet the exact same code isn't working on form 3.
Here it is

 private void button2_Click(object sender, EventArgs e)
        {
            int userNumber = 0;
            int answerSubtract = 0;
            int numberOne = 13;

            if (int.TryParse(textBox1.Text, out userNumber))

                answerSubtract = userNumber - numberOne;

            MessageBox.Show(answerSubtract.ToString());
        }



How would I go about getting this code to work on form3?

Is This A Good Question/Topic? 0
  • +

Replies To: Subtraction not working on form 3

#2 janne_panne  Icon User is offline

  • WinRT Dev
  • member icon

Reputation: 428
  • View blog
  • Posts: 1,047
  • Joined: 09-June 09

Re: Subtraction not working on form 3

Posted 09 October 2012 - 03:49 AM

What do you mean with "not working"? What outcome do you receive? Crash, compile time error or incorrect result?

Have you tried debugging it?

Make sure you have TextBox called textBox1 on Form3, as well as button2 (and button2's Click event is set to button2_Click method).
Was This Post Helpful? 1
  • +
  • -

#3 eclipsed4utoo  Icon User is offline

  • Not Your Ordinary Programmer
  • member icon

Reputation: 1526
  • View blog
  • Posts: 5,961
  • Joined: 21-March 08

Re: Subtraction not working on form 3

Posted 09 October 2012 - 08:28 AM

Simply copying and pasting event handlers between forms is not going to work. You need to make sure you wire the events to the correct UI elements. So, even though you copied button2_Click event to Form3, if you don't have a button on the screen or that button's Click event handler isn't button2_Click, then your code isn't going to run.
Was This Post Helpful? 0
  • +
  • -

#4 risky14  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 21
  • Joined: 12-September 12

Re: Subtraction not working on form 3

Posted 10 October 2012 - 03:52 AM

View Posteclipsed4utoo, on 09 October 2012 - 08:28 AM, said:

Simply copying and pasting event handlers between forms is not going to work. You need to make sure you wire the events to the correct UI elements. So, even though you copied button2_Click event to Form3, if you don't have a button on the screen or that button's Click event handler isn't button2_Click, then your code isn't going to run.


Form 3 is exactly the same as form2 I just couldnt find a way to hold information in form2 and show a certain piece of info based on the users actions. So form 2 has exactly the same properties as form3 that's why I copied and pasted it.

View Postjanne_panne, on 09 October 2012 - 03:49 AM, said:

What do you mean with "not working"? What outcome do you receive? Crash, compile time error or incorrect result?

Have you tried debugging it?

Make sure you have TextBox called textBox1 on Form3, as well as button2 (and button2's Click event is set to button2_Click method).


sorry I should've explained a bit better. On form 2 if I type any number lets say 7 and click button2 the result is 1. Yet I type in any number on form3 and when I click button2 the result doesnt show up in the popup box
Was This Post Helpful? 0
  • +
  • -

#5 Skydiver  Icon User is offline

  • Code herder
  • member icon

Reputation: 3667
  • View blog
  • Posts: 11,500
  • Joined: 05-May 12

Re: Subtraction not working on form 3

Posted 10 October 2012 - 04:30 AM

View Postrisky14, on 10 October 2012 - 03:52 AM, said:

sorry I should've explained a bit better. On form 2 if I type any number lets say 7 and click button2 the result is 1. Yet I type in any number on form3 and when I click button2 the result doesnt show up in the popup box


Do you mean that the popup box displays "0"? Or do you mean that the popup box does not appear at all?

If the latter, as mentioned above, you need to also hookup the events. You can't just copy and paste.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1