[Windows Form with visual C#] - Problem with data conversion
-
Hello to all, now I expose my problem: I'm developing a program with Visual C# express to calculate the ratio of my radio-controlled model! How do I enter the following input data: Number of teeth of spur gear (int), internal ratio (float), and ratio that you want to get (float). I need as output the number of teeth of the pinion to use. The pinion is obtained with the following formula: Pinion = (Spur Gear * Ratio) / Internal Ratio My problem is that I don' t know how to operate the data conversions, because obviously I can' t write:
Int SpurGear = textbox1.Text;
Float Ratio = textbox2.Text;
Float InternalRatio= textbox3.Text;
Float Pinion = (SpurGear * Ratio) / InternalRatio;
label1.text= Pinion;Etc Etc Someone can help me?
-
Hello to all, now I expose my problem: I'm developing a program with Visual C# express to calculate the ratio of my radio-controlled model! How do I enter the following input data: Number of teeth of spur gear (int), internal ratio (float), and ratio that you want to get (float). I need as output the number of teeth of the pinion to use. The pinion is obtained with the following formula: Pinion = (Spur Gear * Ratio) / Internal Ratio My problem is that I don' t know how to operate the data conversions, because obviously I can' t write:
Int SpurGear = textbox1.Text;
Float Ratio = textbox2.Text;
Float InternalRatio= textbox3.Text;
Float Pinion = (SpurGear * Ratio) / InternalRatio;
label1.text= Pinion;Etc Etc Someone can help me?
Try:
Int SpurGear = int.Parse(textbox1.Text);
Float Ratio = Float.Parse(textbox2.Text);
Float InternalRatio= Float.Parse(textbox3.Text);
Float Pinion = ((Float) SpurGear * Ratio) / InternalRatio;
label1.text= Pinion.ToString();No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
Hello to all, now I expose my problem: I'm developing a program with Visual C# express to calculate the ratio of my radio-controlled model! How do I enter the following input data: Number of teeth of spur gear (int), internal ratio (float), and ratio that you want to get (float). I need as output the number of teeth of the pinion to use. The pinion is obtained with the following formula: Pinion = (Spur Gear * Ratio) / Internal Ratio My problem is that I don' t know how to operate the data conversions, because obviously I can' t write:
Int SpurGear = textbox1.Text;
Float Ratio = textbox2.Text;
Float InternalRatio= textbox3.Text;
Float Pinion = (SpurGear * Ratio) / InternalRatio;
label1.text= Pinion;Etc Etc Someone can help me?
Most of the value types have Parse method for data conversion. Don't forget to have a look at TryParse methods too :)
Giorgi Dalakishvili #region signature My Articles Asynchronous Registry Notification Using Strongly-typed WMI Classes in .NET [^] My blog #endregion
-
Try:
Int SpurGear = int.Parse(textbox1.Text);
Float Ratio = Float.Parse(textbox2.Text);
Float InternalRatio= Float.Parse(textbox3.Text);
Float Pinion = ((Float) SpurGear * Ratio) / InternalRatio;
label1.text= Pinion.ToString();No trees were harmed in the sending of this message; however, a significant number of electrons were slightly inconvenienced. This message is made of fully recyclable Zeros and Ones
-
Hello to all, now I expose my problem: I'm developing a program with Visual C# express to calculate the ratio of my radio-controlled model! How do I enter the following input data: Number of teeth of spur gear (int), internal ratio (float), and ratio that you want to get (float). I need as output the number of teeth of the pinion to use. The pinion is obtained with the following formula: Pinion = (Spur Gear * Ratio) / Internal Ratio My problem is that I don' t know how to operate the data conversions, because obviously I can' t write:
Int SpurGear = textbox1.Text;
Float Ratio = textbox2.Text;
Float InternalRatio= textbox3.Text;
Float Pinion = (SpurGear * Ratio) / InternalRatio;
label1.text= Pinion;Etc Etc Someone can help me?
Hi, a TextBox contains text, so Text returns a string, not a number. converting strings to some numeric type is called parsing, use the Parse or TryParse method of the target type, e.g.
double.TryParse(...)
, see documentation. :)Luc Pattyn
I only read code that is properly indented, and rendered in a non-proportional font; hint: use PRE tags in forum messages