#1
  1. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    64
    Rep Power
    12

    Whats wrong with my if-clause?


    Code:
    if (textBox1->Text=="Delete")
    {
      label1->Text="Delete will start soon";
    }
    else
    {
     label1->Text="Error";
    }
    I alway get "Error" although I entered Delete in textBox1! What´s wrong?
  2. #2
  3. not a fan of fascism (n00b)
    Devshed Frequenter (2500 - 2999 posts)

    Join Date
    Feb 2003
    Location
    ct
    Posts
    2,756
    Rep Power
    95
    when you compare strings, you need to use strcmp().
    http://www.qnx.com/developer/docs/qn.../s/strcmp.html
  4. #3
  5. jasondoucette.com
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Canada
    Posts
    378
    Rep Power
    12
    Since I am not sure if you are using a class that overloads the operators, my answer may not be accurate:

    You are attempting to compare a string with another string. However, since strings are really just pointers to some memory location that has a bunch of characters terminated with a NULL character, what you are actually comparing are pointers. Unless both pointers contain the same value (and thus point to the SAME memory - regardless of what string is actually stored there), then you will get 'false' from this comparison.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jun 2003
    Posts
    109
    Rep Power
    12
    Code:
    if(String::Compare(textBox1->Text, "Delete") == 0)
    {
    	label1->Text = "Delete will start soon";
    }
    else
    {
    	label1->Text = "Error";
    }
  8. #5
  9. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    64
    Rep Power
    12
    THQ Nem!

IMN logo majestic logo threadwatch logo seochat tools logo