small program


New member
Apr 12, 2013
Programming Experience
I dont want to look stupid or anything but I need some help with a small program I have to write as a test.

What I need to do is to make sure someone can type any value of number in the textbox and the value must be added to the int value I set in the beginning when clicked on the button.

How do I get started and how do I convert int to string, and how do I make the button and textbox talk to eachother?

I'm still in the beginning of my studies so bear with me for now please
You don't make the Button and TextBox talk to each other. Everything is done by the form. The Button raises its Click event to notify the form that the user clicked the Button and that is the sum total of what the Button does. The TextBox exposes the text entered by the user via its Text property and that's the sum total of what the TextBox does. All the work is done by the form. The form handles the Click event of the Button and, in the event handler, gets the Text property of the TextBox. It then does whatever is appropriate with that data.

In your case, you should probably use the int.TryParse method or double.TryParse method, depending on whether you want to allow fractional values or just whole numbers. Each will validate the input and notify you if it fails, then convert it if it passes. You can then use the resulting number in your mathematical calculations.

Latest posts

Top Bottom