Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. [Windows Form with visual C#] - Problem with data conversion

[Windows Form with visual C#] - Problem with data conversion

Scheduled Pinned Locked Moved C#
helpquestioncsharptutorial
5 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • _ Offline
    _ Offline
    _ASPAle_
    wrote on last edited by
    #1

    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?

    OriginalGriffO G L 3 Replies Last reply
    0
    • _ _ASPAle_

      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?

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      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

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      _ 1 Reply Last reply
      0
      • _ _ASPAle_

        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?

        G Offline
        G Offline
        Giorgi Dalakishvili
        wrote on last edited by
        #3

        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

        1 Reply Last reply
        0
        • OriginalGriffO OriginalGriff

          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

          _ Offline
          _ Offline
          _ASPAle_
          wrote on last edited by
          #4

          Ok thank you very much, now I try it!

          1 Reply Last reply
          0
          • _ _ASPAle_

            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?

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            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


            1 Reply Last reply
            0
            Reply
            • Reply as topic
            Log in to reply
            • Oldest to Newest
            • Newest to Oldest
            • Most Votes


            • Login

            • Don't have an account? Register

            • Login or register to search.
            • First post
              Last post
            0
            • Categories
            • Recent
            • Tags
            • Popular
            • World
            • Users
            • Groups