We'd like to remind Forumites to please avoid political debate on the Forum. This is to keep it a safe and useful space for MoneySaving discussions. Threads that are - or become - political in nature may be removed in line with the Forum’s rules. Thank you for your understanding.

IF Statement

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

Categories

  • All Categories
  • 346K Banking & Borrowing
  • 251.1K Reduce Debt & Boost Income
  • 451.1K Spending & Discounts
  • 238.1K Work, Benefits & Business
  • 613.2K Mortgages, Homes & Bills
  • 174.5K Life & Family
  • 251.3K Travel & Transport
  • 1.5M Hobbies & Leisure
  • 16K Discuss & Feedback
  • 15.1K Coronavirus Support 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.