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
Dude
Posts: 206 Forumite
in Techie Stuff
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.
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!
0
Comments
-
It is much better if you have the key words IF, ELSE, END IF in CAPS that way you can see it better.0
-
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 thisIF 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.0 -
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.0 -
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
ELSEIF ... THENEND IF
ELSE
END IFCharlie0
This discussion has been closed.
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