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

You can't do an addition and xor at the same time

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.

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 ?

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.