private: System::Void btnAdd_Click(System::Object^ sender, System::EventArgs^ e) { //---create three variables for our data double firstNumber = 0; double secondNumber = 0; double totalDue = 0; /* assign the values to variables using TryParse. If TryParse can convert the value in the textbox to a double, then it assigns that value to the variable automatically so I do not have to! This will block alpha characters or invalid data. Notice I use && so if the first expression is false it doesn't waste time checking the second expression.*/ if(Double::TryParse(txt1->Text, firstNumber) && Double::TryParse(txt2->Text, secondNumber)) { totalDue = firstNumber + secondNumber; //'add them Label1->Text = DoFormat(totalDue); //let DoFormat function format as currency } else { MessageBox::Show("Please enter correct data."); ClearForm(); } } private: System::String^ DoFormat(double x) { String^ myResult = x.ToString("c"); return myResult; }