We'd like to remind Forumites to please avoid political debate on the Forum... Read More »
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

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.
Confirm your email address to Create Threads and Reply

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