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. Managed C++/CLI
  4. I get Input string was not in a correct format. error

I get Input string was not in a correct format. error

Scheduled Pinned Locked Moved Managed C++/CLI
help
4 Posts 3 Posters 2 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.
  • S Offline
    S Offline
    Soren Lyder Nielsen
    wrote on last edited by
    #1

    I Get this error, when I write a number in my textBox1, and then erase it again.. Then this popup appers: An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format. Code:

    private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
    double tysk, ti, femten, tyve, dansk;
    tysk = System::Convert::ToDouble(textBox1->Text);

             dansk = tysk \* 7.5;
             ti = tysk \* 7.5 \* 0.90;
             femten = tysk \* 7.5 \* 0.85;
             tyve = tysk \* 7.5\* 0.80;
             
             label7->Text = System::Convert::ToString(dansk);
             label8->Text = System::Convert::ToString(ti);
             label9->Text = System::Convert::ToString(femten);
             label10->Text = System::Convert::ToString(tyve);
         }
    

    };

    It also appers when I type a letter in the teksBox1. Otherwise it workd fine. Its just a simlpe calculator.

    L U 3 Replies Last reply
    0
    • S Soren Lyder Nielsen

      I Get this error, when I write a number in my textBox1, and then erase it again.. Then this popup appers: An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format. Code:

      private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
      double tysk, ti, femten, tyve, dansk;
      tysk = System::Convert::ToDouble(textBox1->Text);

               dansk = tysk \* 7.5;
               ti = tysk \* 7.5 \* 0.90;
               femten = tysk \* 7.5 \* 0.85;
               tyve = tysk \* 7.5\* 0.80;
               
               label7->Text = System::Convert::ToString(dansk);
               label8->Text = System::Convert::ToString(ti);
               label9->Text = System::Convert::ToString(femten);
               label10->Text = System::Convert::ToString(tyve);
           }
      

      };

      It also appers when I type a letter in the teksBox1. Otherwise it workd fine. Its just a simlpe calculator.

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      tysk = System::Convert::ToDouble(textBox1->Text);

      This will always throw an exception if the contents of teksBox1 is not a number. You should either catch the exception and deal with it, or use the TryParse[^] method.

      Use the best guess

      1 Reply Last reply
      0
      • S Soren Lyder Nielsen

        I Get this error, when I write a number in my textBox1, and then erase it again.. Then this popup appers: An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format. Code:

        private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
        double tysk, ti, femten, tyve, dansk;
        tysk = System::Convert::ToDouble(textBox1->Text);

                 dansk = tysk \* 7.5;
                 ti = tysk \* 7.5 \* 0.90;
                 femten = tysk \* 7.5 \* 0.85;
                 tyve = tysk \* 7.5\* 0.80;
                 
                 label7->Text = System::Convert::ToString(dansk);
                 label8->Text = System::Convert::ToString(ti);
                 label9->Text = System::Convert::ToString(femten);
                 label10->Text = System::Convert::ToString(tyve);
             }
        

        };

        It also appers when I type a letter in the teksBox1. Otherwise it workd fine. Its just a simlpe calculator.

        L Offline
        L Offline
        Lost User
        wrote on last edited by
        #3

        Look this Example .. it will help.

        int a= Convert::ToInt32(this->textBox1->Text->Trim());
        int b= Convert::ToInt32(this->textBox2->Text->Trim());
        int sum=a+b;

        "The more quieter you become, the more you are able to hear..."

        1 Reply Last reply
        0
        • S Soren Lyder Nielsen

          I Get this error, when I write a number in my textBox1, and then erase it again.. Then this popup appers: An unhandled exception of type 'System.FormatException' occurred in mscorlib.dll Additional information: Input string was not in a correct format. Code:

          private: System::Void textBox1_TextChanged(System::Object^ sender, System::EventArgs^ e) {
          double tysk, ti, femten, tyve, dansk;
          tysk = System::Convert::ToDouble(textBox1->Text);

                   dansk = tysk \* 7.5;
                   ti = tysk \* 7.5 \* 0.90;
                   femten = tysk \* 7.5 \* 0.85;
                   tyve = tysk \* 7.5\* 0.80;
                   
                   label7->Text = System::Convert::ToString(dansk);
                   label8->Text = System::Convert::ToString(ti);
                   label9->Text = System::Convert::ToString(femten);
                   label10->Text = System::Convert::ToString(tyve);
               }
          

          };

          It also appers when I type a letter in the teksBox1. Otherwise it workd fine. Its just a simlpe calculator.

          U Offline
          U Offline
          User 9966263
          wrote on last edited by
          #4

          Use this instead of "Convert::ToString()" function int a = 287; String ^b = ""; b += a;

          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