Hello, I have Visual C++ 2008 in a Windows 7.

I wanna get the value from a textbox to an int, after that I wanna make some operations with the int like + or - or * or / and I want to write it to an another textbox. And to save the int to a file.
I tryed:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             int ^ a;
             a = Convert::ToInt32(textBox1->Text);

here is the error:

a=a+^5;
             textBox2->Text=Convert::ToString(a);
}

BUT I GET ERROR

Edited 3 Years Ago by Reverend Jim: Fixed formatting

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
int ^ a;
a = Convert::ToInt32(textBox1->Text);
here is the error: a=a+5;
textBox2->Text=Convert::ToString(a);
}

now it get error ...

Use Int32::TryParse instead of the Convert call. It's safer and it will return false if it fails versus throwing an exception. You'll have to have a tracking reference int % aout = a; to get the value back from TryParse, but declare "a" as a regular old int and you should be able to call ToString() on it directly.

Edited 6 Years Ago by jonsca: n/a

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             String ^ strTextBoxContent;
             int % aout = a;
             a = Int32::TryParse(textBox1->Text);
            /*  textBox2->Text=strTextBoxContent;; */

            a=a+5;
            textBox2->Text=Convert::ToString(a);


         }

SO I changed but now I have 6 errors Could U write the correct version plz ?

Edited 3 Years Ago by Reverend Jim: Fixed formatting

Now I have 1 error:

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             String ^ strTextBoxContent;
             int  a;
             int % aout = a;

here is the error:

a = Int32::TryParse(textBox1->Text);
            /*  textBox2->Text=strTextBoxContent;; */

            a=a+5;
            textBox2->Text=Convert::ToString(a);
        }

error C2661: 'System::Int32::TryParse' : no overloaded function takes 1 arguments

Edited 3 Years Ago by Reverend Jim: Fixed formatting

It WORK :D

private: System::Void button1_Click(System::Object^  sender, System::EventArgs^  e) {
             String ^ strTextBoxContent;
             int  a;
             int % aout = a;
            Int32::TryParse(textBox1->Text,a);
            /*  textBox2->Text=strTextBoxContent;; */
            a=a+7;
            textBox2->Text=Convert::ToString(a);
        }

THX for your help u are amazing :D THX

Edited 3 Years Ago by Reverend Jim: Fixed formatting

This article has been dead for over six months. Start a new discussion instead.