RAIN_13
RAIN_13

Reputation: 11

I am having a problem with textboxes in window's forms feature in c++

Im pretty new to c++ and im building a calculator with the windows forms feature. I have made the UI and the UI consists of the user entering digits into the 2 text boxes and after that then the 2 numbers will be added together but I am having this problem and here is the code

    private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
        int ^ FirstNumber = textbox1->Text;
        int ^ SecondNumber = textBox3->Text;
        int ^ Result = FirstNumber + SecondNumber;
    }

Here are my Errors: Errors

Does anyone know a fix?? I am also having an error when I add the two var's together.

Upvotes: 1

Views: 58

Answers (1)

hammus
hammus

Reputation: 2612

You need to convert the Textbox strings to ints also you probably dont want managed pointers to those values. Something like this should work (untested):

private: System::Void button1_Click(System::Object^ sender, System::EventArgs^ e) {
        int FirstNumber =  System::Convert::ToInt32(textBox1->Text);
        int SecondNumber = System::Convert::ToInt32(textBox3->Text);
        int Result = FirstNumber + SecondNumber;
    }

Edit: As @Robert Harvey pointed out in the comments, the first error is likely because textbox1 likely should have been textBox1 but without seeing the rest of the class code its difficult to say

Upvotes: 1

Related Questions