We're aware that some users are experiencing technical issues which the team are working to resolve. Thank you for your patience.
📨 Have you signed up to the Forum's new Email Digest yet? Get a selection of trending threads sent straight to your inbox daily, weekly or monthly!

IF Statement

Options
Being very new to programming I am struggling with writing the conditional logic for a simple IF statement.

I have a stylesheet switcher which stores the users style preference in a cookie. I am having a problem if the user has not been to the site before or cleared there cookies. In this instance I would like to default to styles.css.
Session("stylesheet")=request.Cookies("stylesheet")
if request.QueryString("stylesheet") = "styles" then
Session("stylesheet")="styles.css"
elseif request.QueryString("stylesheet") = "blackonwhite" then
Session("stylesheet")="blackonwhite.css"
else
Session("stylesheet")="styles.css"
end if
2 heads are better than 1….unless they are on the same body!

Comments

  • It is much better if you have the key words IF, ELSE, END IF in CAPS that way you can see it better.
  • Cypher
    Cypher Posts: 440 Forumite
    also indent the code so you can see which bit is with what (not sure if its the forum thats missed out the indentation.)

    looking at your code you could simplfy your conditions to this
    IF requested style <> blackonwhite  THEN
       set style to standard style
    ELSE
      set style to blackonwhite
    END IF
    

    the above is not the real code just the idea.
  • johnmc
    johnmc Posts: 1,265 Forumite
    No gap between "else" and "if". Two IF's and only one ENDIF.

    It's good practise to use CAPS for reserved words and to indent, as per the above, as it makes debugging easier.

    HTH.
  • f1charlie
    f1charlie Posts: 1,228 Forumite
    I don't know which languauge this is, but one ENDIF is correct if it supports ELSEIF:

    IF ... THEN

    ELSEIF .... THEN

    ELSE

    ENDIF

    Otherwise it would be clearer as:

    IF ... THEN

    ELSE
    IF ... THEN

    ELSE

    END IF
    END IF
    Charlie
This discussion has been closed.
Meet your Ambassadors

🚀 Getting Started

Hi new member!

Our Getting Started Guide will help you get the most out of the Forum

Categories

  • All Categories
  • 350.6K Banking & Borrowing
  • 253K Reduce Debt & Boost Income
  • 453.4K Spending & Discounts
  • 243.6K Work, Benefits & Business
  • 598.4K Mortgages, Homes & Bills
  • 176.8K Life & Family
  • 256.8K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16.1K Discuss & Feedback
  • 37.6K Read-Only Boards

Is this how you want to be seen?

We see you are using a default avatar. It takes only a few seconds to pick a picture.