Results 1 to 8 of 8

Thread: [RESOLVED] What is wrong with this statement?

  1. #1

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Resolved [RESOLVED] What is wrong with this statement?

    My code:


    Single PVal, TotPmts, Payment, Fmt, APR, APR2, PayType, FVal;
    const int ENDPERIOD = 0;
    const int BEGINPERIOD = 0;

    --I will add code here later to get input data

    If (APR > 1) then APR2 = APR / 100;
    APR2 = APR2 / 12;


    The "then" is underlined with the following message:

    "; expected"
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  2. #2
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: What is wrong with this statement?

    There is no "Then" in an If statement like in VB.

    Code:
                if (APR > 1)
                {
                    APR2 = APR / 100;
                }
                else
                {
                    MessageBox.Show("APR is not greater than 1.");
                }

  3. #3

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: What is wrong with this statement?

    I get the same error with this :

    If (APR > 1)
    APR2 = APR / 100;
    APR2 = APR2 / 12;
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  4. #4

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: What is wrong with this statement?

    Got it. "If" is not the same as "if". C# will take some getting used to. :-)
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  5. #5
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: What is wrong with this statement?

    Quote Originally Posted by Pasvorto
    Got it. "If" is not the same as "if". C# will take some getting used to. :-)
    That's right.


    Also note that this:
    Code:
                if (1 == 2)
                MessageBox.Show("What? 1 equals 2? I bet you don't see this message box.");
                MessageBox.Show("Hi there. You do see me.");
    is not the same as this:
    Code:
                if (1 == 2)
                {
                    MessageBox.Show("What? 1 equals 2? I bet you don't see this message box.");
                    MessageBox.Show("Now you don't see me either.");
                }
    If you do not include the brackets, the if statement is only checking the first line. Personally I always use them as it is just clearer to me.
    APR2 = APR2 / 12; in your code is always going to execute.

  6. #6

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: [RESOLVED] What is wrong with this statement?

    I want the APR2 = APR2 / 12 to always execute.
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

  7. #7
    Registered User nmadd's Avatar
    Join Date
    Jun 2007
    Location
    U.S.A.
    Posts
    1,676

    Re: [RESOLVED] What is wrong with this statement?

    Quote Originally Posted by Pasvorto
    I want the APR2 = APR2 / 12 to always execute.
    Ok then. It will.

  8. #8

    Thread Starter
    PowerPoster Pasvorto's Avatar
    Join Date
    Oct 2002
    Location
    Minnesota, USA
    Posts
    2,951

    Re: [RESOLVED] What is wrong with this statement?

    Another hurdle overcome...
    ===================================================
    If your question has been answered, mark the thread as [RESOLVED]

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width