SO simple..but?

  • Thread starter Thread starter den.NET
  • Start date Start date
D

den.NET

assume i have 2 text boxes in the visual studio windows form c++.NET
2003.and there is a button adding the values entered the
textboxes.but i forget to fill one and push the button.it gives me an
error.how can i get rid of this?how can i define the code in the
button that the textbox is null(or empty)?as i said,it is so simple
and i am also a newbie;).thank u anyone who cares.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*
 
den.NET said:
assume i have 2 text boxes in the visual studio windows form c++.NET
2003.and there is a button adding the values entered the
textboxes.but i forget to fill one and push the button.it gives me an
error.how can i get rid of this?how can i define the code in the
button that the textbox is null(or empty)?as i said,it is so simple
and i am also a newbie;).thank u anyone who cares.

*-----------------------*
Posted at:
www.GroupSrv.com
*-----------------------*

Here's a way to trap any input error, not just lack of input. Assuming
textBox1 and textBox2 are for input to the addition problem:

private: System::Void button1_Click(System::Object * sender,
System::EventArgs * e)

{

double d1, d2, d3;

try

{

d1 = Convert::ToDouble(textBox1->Text);

d2 = Convert::ToDouble(textBox2->Text);

}

catch (Exception* e)

{

d1 = 0;

d2 = 0;

MessageBox::Show(e->Message);

textBox1->Clear();

textBox2->Clear();

textBox1->Focus();

}

d3 = d1 + d2;

textBox3->Text = Convert::ToString(d3);


}

Obviously, this can be greatly improved, but I hope it gives you the idea.
 
Something like this:

if ( (textBox1->Text)->CompareTo("") == 0 )
{
textBox1->Text = "Text box one empty";
}
 
Back
Top