The intended behaviour is:
1. Passing strings of numbers using the numbered buttons (1..0).
2. Concatenate the strings above into one and converting it into an integer.
3. Select an operation ( +, -, * and /)
4. Passing strings of numbers using the numbered buttons (1..0).
5. Concatenate the strings above into one and converting it into an integer.
6. Perform the calculation and output the result to the same textbox.
The actual behaviour:
1. The program works well with single digits.
2. The problem starts when I use 2 digit numbers. The first click on the buttons displays the correct number in the text box.
3. When I click a second time to add a second digit the first value is over written with the new value.
4. The third click (number selection) adds the intended number correctly.
Samples of my code that perform the main operations:
A typical numbered button calls the method constructString:
Expand|Select|Wrap|Line Numbers
- private void button8_Click(object sender, EventArgs e)
- {
- int j = 2;
- string s = j.ToString();
- constructString(s);
- }
- constructString builds the string, saves it into the variable nubString and passes it to textbox
- private void constructString(String str)
- {
- if (numString == null)
- {
- numString = str;
- }
- else
- {
- numString = numString + str;
- }
- textBox1.Text = numString;
- }
- This is followed by the following:
- private void textBox1_TextChanged(object sender, EventArgs e)
- {
- if (textBox1.Text != null && numString != null)
- {
- if (counter == 0)
- {
- v1 = PNNumber(numString);
- //for test purposes
- textBox3.Text = v1.ToString();
- numString = null;
- counter++;
- }
- else
- {
- v2 = PNNumber(numString);
- // for test purposes
- textBox3.Text = v2.ToString();
- numString = null;
- counter = 0;
- }
- }
- }