"if" confusion

This is a discussion on "if" confusion within the Windows Programming forums, part of the Platform Specific Boards category; I'm working on a program. This function you are about to see is a button. When the button is pressed, ...

  1. #1
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    892

    "if" confusion

    I'm working on a program. This function you are about to see is a button. When the button is pressed, the program checks to see how two edit boxes are doing and then answers them. The problem is, the first if statement always executes, even if it shouldn't. What's wrong?


    void PasswordChange::OnOK()
    {
    if(m_OldPassword.IsEmpty() == TRUE && m_NewPassword.IsEmpty() == TRUE)
    {
    MessageBox("Both are empty");
    CDialog::OnOK();
    }
    else
    {
    }
    if(m_OldPassword.IsEmpty() == FALSE && m_NewPassword.IsEmpty() == TRUE)
    {
    MessageBox("New Is Empty");
    CDialog::OnOK();
    }
    else
    {
    }
    CDialog::OnOK();
    }
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  2. #2
    Registered User
    Join Date
    Oct 2001
    Posts
    10
    try to compare the contains of the edit box with ""
    like
    if(edit1.text == "" && edit2.text == "")
    {
    // for the things i used use your own
    }
    If You've Be Biten By DaRk$nAkE The Only Things You Will See R Bytes

  3. #3
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    892
    That won't work, because the if is checking to see "IF" a function is true. The " 's don't belong.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

  4. #4
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,856
    Break it down.

    Catch the returns from both the functions into temp ints. You will then see what is going on.

    We know that the IF function works so there must be a problem with the returns from one of the functions or in the capture of the passwords.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

  5. #5
    the hat of redundancy hat nvoigt's Avatar
    Join Date
    Aug 2001
    Location
    Hannover, Germany
    Posts
    3,138
    Your function is probably running perfectly. Both strings are empty. You need to update the data and let the framework call the functions that link the string variables to the textboxes.

    Code:
    void PasswordChange::OnOK() 
    { 
          UpdateData(); // Important !!!
    
         // yourstuff here
    hth
    -nv

    She was so Blonde, she spent 20 minutes looking at the orange juice can because it said "Concentrate."

    When in doubt, read the FAQ.
    Then ask a smart question.

  6. #6
    Kiss the monkey. CodeMonkey's Avatar
    Join Date
    Sep 2001
    Posts
    892
    Thanks, nvoigt.
    "If you tell the truth, you don't have to remember anything"
    -Mark Twain

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Pointer confusion
    By rits in forum C Programming
    Replies: 3
    Last Post: 03-12-2009, 08:00 AM
  2. a Bit of confusion (haha - Pun)
    By Junior89 in forum C++ Programming
    Replies: 1
    Last Post: 06-15-2007, 11:22 PM
  3. C++ Classes: Use, Misuse...Confusion.
    By Snorpy_Py in forum C++ Programming
    Replies: 4
    Last Post: 10-23-2006, 01:46 AM
  4. for loop confusion
    By Enges in forum C++ Programming
    Replies: 6
    Last Post: 04-26-2006, 08:21 AM
  5. confusion with increment and decrement operators
    By cBegginer in forum C Programming
    Replies: 6
    Last Post: 03-19-2005, 02:45 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21