SO simple..but?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • den.NET

    SO simple..but?

    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:

    *-----------------------*
  • Peter Jausovec

    #2
    Re: SO simple..but?

    Hi,

    Just check if your textbox is empty. (if (textBox.Text == ""))

    --
    Regards,
    Peter Jausovec
    (http://blog.jausovec.net)
    "den.NET" <dentaro@wall a-dot-com.no-spam.invalid> je napisal v sporocilo
    news:41b85943$1 _4@Usenet.com ...[color=blue]
    > 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
    > *-----------------------*[/color]


    Comment

    • Peter van der Goes

      #3
      Re: SO simple..but?


      "den.NET" <dentaro@wall a-dot-com.no-spam.invalid> wrote in message
      news:41b85943$1 _4@Usenet.com.. .[color=blue]
      > 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
      > *-----------------------*[/color]

      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(S ystem::Object * sender,
      System::EventAr gs * e)

      {

      double d1, d2, d3;

      try

      {

      d1 = Convert::ToDoub le(textBox1->Text);

      d2 = Convert::ToDoub le(textBox2->Text);

      }

      catch (Exception* e)

      {

      d1 = 0;

      d2 = 0;

      MessageBox::Sho w(e->Message);

      textBox1->Clear();

      textBox2->Clear();

      textBox1->Focus();

      }

      d3 = d1 + d2;

      textBox3->Text = Convert::ToStri ng(d3);


      }

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


      --
      Peter [MVP Visual Developer]
      Jack of all trades, master of none.


      Comment

      • Ben Solomon

        #4
        RE: SO simple..but?

        Something like this:

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


        "den.NET" wrote:
        [color=blue]
        > 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
        > *-----------------------*
        >[/color]

        Comment

        Working...