[Beginners]Working With Number Variables in C# 06-05-2013, 07:27 AM
#1
Hey you guys, Today I am going to teach you how to do this:
Okay Since you either watched that, or didnt, Lets make this fast, if you did not see my last tutorial on variables and messagebox's then please go look at that one, now lets get started, Make a new form in C# and add:
1 GroupBox
1 Textbox
1 Button
You can name them whatever, but this is what my setup looked like
![[Image: Screenshot.png]](http://i1126.photobucket.com/albums/l604/Kaopio14/Screenshot.png)
Now double click on the button and add this code:
![[Image: Screenshot2.png]](http://i1126.photobucket.com/albums/l604/Kaopio14/Screenshot2.png)
Now you may not understand this code but its okay! Undead is here to help you. int is short for integer (i skipped string because i showed that in the last tutorial) Now, since you have that down, and integer is a full number and that is what we are using right here. a number. There is Floats and Doubles, but i am not going over that because Integers are mostly used.
now you see this code
Now , int.Parse is prretty much converting the String (humanyears) into an integer, and then you dont have to do that to dogyears because it is already and intger!!!!!
Then if you look at the messagebox code the one that might confuse you is why i went, answer.ToString()... that is because i am converting answer( that is an integer) into a string, so C# won't give you an error, the reason why it would give you an error is because it is not a string, and messagebox's runs through Strings, not integers. Now for the next layout, i do not have a screenshot of it, but under the first groupBox, add these:
1 GroupBox
2 Textbox's
2 Labels
1 Button
Change the groupbox text to: Age Difference,
Change the Textbox's and Labels so that Label one lines up with Textbox 2 (or textbox 1 according to inside the groupbox) then line label2 up with Textbox3 (or textbox2 according to inside the groupbox)
Name label1: Your Age:
and label2: Other Age:
now name the button: Calculate
Open the code to the button and add this code:
![[Image: Screenshot4.png]](http://i1126.photobucket.com/albums/l604/Kaopio14/Screenshot4.png)
Now, you should be able to understand all that code, just study it, i am not going to explain it, because anything that is in here, i explained all in the first tutorial and this tutorial. and the - sign is to minus your age from the other age, so now the program should look like this:
![[Image: Screenshot5.png]](http://i1126.photobucket.com/albums/l604/Kaopio14/Screenshot5.png)
Now after that, add:
1 groupbox
1 textbox
1 button
change the groupbox text to , Convert C to F
change the button text to, Convert
Then add this code into the button:
![[Image: Screenshot6.png]](http://i1126.photobucket.com/albums/l604/Kaopio14/Screenshot6.png)
Now the only reason why i didnt put the 2 and the 32 in a variable is because you dont always have to do that! i just wanted you to learn Variables. Also you might not know the conversion from C to F but now you do, its C times 2 plus 32 but the real one is that its C times 9/10 {nine over ten} plus 32. So now the full program should look like:
![[Image: Screenshot7.png]](http://i1126.photobucket.com/albums/l604/Kaopio14/Screenshot7.png)
Woo that was long, and im done with this tutorial, hoped this helped any.
Okay Since you either watched that, or didnt, Lets make this fast, if you did not see my last tutorial on variables and messagebox's then please go look at that one, now lets get started, Make a new form in C# and add:
1 GroupBox
1 Textbox
1 Button
You can name them whatever, but this is what my setup looked like
![[Image: Screenshot.png]](http://i1126.photobucket.com/albums/l604/Kaopio14/Screenshot.png)
Now double click on the button and add this code:
![[Image: Screenshot2.png]](http://i1126.photobucket.com/albums/l604/Kaopio14/Screenshot2.png)
Now you may not understand this code but its okay! Undead is here to help you. int is short for integer (i skipped string because i showed that in the last tutorial) Now, since you have that down, and integer is a full number and that is what we are using right here. a number. There is Floats and Doubles, but i am not going over that because Integers are mostly used.
now you see this code
Code:
answer = int.Parse(humanyears) * dogyears;
Then if you look at the messagebox code the one that might confuse you is why i went, answer.ToString()... that is because i am converting answer( that is an integer) into a string, so C# won't give you an error, the reason why it would give you an error is because it is not a string, and messagebox's runs through Strings, not integers. Now for the next layout, i do not have a screenshot of it, but under the first groupBox, add these:
1 GroupBox
2 Textbox's
2 Labels
1 Button
Change the groupbox text to: Age Difference,
Change the Textbox's and Labels so that Label one lines up with Textbox 2 (or textbox 1 according to inside the groupbox) then line label2 up with Textbox3 (or textbox2 according to inside the groupbox)
Name label1: Your Age:
and label2: Other Age:
now name the button: Calculate
Open the code to the button and add this code:
![[Image: Screenshot4.png]](http://i1126.photobucket.com/albums/l604/Kaopio14/Screenshot4.png)
Now, you should be able to understand all that code, just study it, i am not going to explain it, because anything that is in here, i explained all in the first tutorial and this tutorial. and the - sign is to minus your age from the other age, so now the program should look like this:
![[Image: Screenshot5.png]](http://i1126.photobucket.com/albums/l604/Kaopio14/Screenshot5.png)
Now after that, add:
1 groupbox
1 textbox
1 button
change the groupbox text to , Convert C to F
change the button text to, Convert
Then add this code into the button:
![[Image: Screenshot6.png]](http://i1126.photobucket.com/albums/l604/Kaopio14/Screenshot6.png)
Now the only reason why i didnt put the 2 and the 32 in a variable is because you dont always have to do that! i just wanted you to learn Variables. Also you might not know the conversion from C to F but now you do, its C times 2 plus 32 but the real one is that its C times 9/10 {nine over ten} plus 32. So now the full program should look like:
![[Image: Screenshot7.png]](http://i1126.photobucket.com/albums/l604/Kaopio14/Screenshot7.png)
Woo that was long, and im done with this tutorial, hoped this helped any.