Integer Calculator Form

  • Thread starter Thread starter Corey Dyke
  • Start date Start date
C

Corey Dyke

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
 
Corey Dyke said:
[...]
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??

Pretty difficult to guess without seeing any of your code.

How are you trying to do it?

P.
 
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.
 
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 said:
Corey Dyke said:
[...]
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??

Pretty difficult to guess without seeing any of your code.

How are you trying to do it?

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

and i have
 
Awesome.
Thanks Johnathan

much appreciated : )

although i should have noticed that myself
hehe

Corey
 
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(object sender, EventArgs e)
{
try
{
asn.Text = (Int32.Parse(num1.Text) +
Int32.Parse(num2.Text)).ToString();
}
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 said:
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 said:
Corey Dyke said:
[...]
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??

Pretty difficult to guess without seeing any of your code.

How are you trying to do it?

P.
 
Back
Top