logo
g Text Version
Beauty & Self
Books & Music
Career
Computers
Education
Family
Food & Wine
Health & Fitness
Hobbies & Crafts
Home & Garden
Money
News & Politics
Relationships
Religion & Spirituality
Sports
Travel & Culture
TV & Movies

dailyclick
Bored? Games!
Nutrition
Postcards
Take a Quiz
Rate My Photo

new
Houseplants
Romance Movies
Creativity
Family Travel
Southwest USA
Irish Culture
Home Finance


dailyclick
All times in EST

Full Schedule
g
g ASP Site

BellaOnline's ASP Editor

g

IF-THEN and CASE statements

Guest Author - Lisa Shea

There are often times that you want to do something different based on the value of a variable. Maybe you want to go to different webpages, or show different prompts on the screen. The if-then and CASE statements help you do that!

When you write code, you often want the code to do something different depending on what a user inputs, what time of day it is, and so on. There are a variety of ways that you can do these sorts of branches in your code. Each is good for a different purpose.

First, the if-then statement. This is the most common in programming, and is the easiest to understand. If something is true, then the code executes. If it's not true, the code does not execute. You can use a 'else' area to execute the 'false' half of the equation.

For example, say you are doing something with a Member. You want to do different things if this is a new member vs an existing member. You would write:

if NewMember = TRUE then
Response.Write "Welcome, new member!"
else
Response.Write "Welcome back, existing member!"
end if

If the top IF line is true, then the code after it executes. If it is false, the 'else' code executes.

The if-then-else works with any kind of variable, not just a true-false one. For example, you could test:

if BooksBought> 50 then
Response.Write "Wow, you must love to read books!"
else
Response.Write "Thank you for buying books from our site."
end if

The next common sort of selection is a CASE statement. You use this if you want to test for various values in a variable without writing if-then-if-then-if-then lots of times. For example, you could do something like this:

select case FavoriteColor
case "Green"
Response.Write "It's not easy being green - but it's a grassy color!"
case "Blue"
Response.Write "Blue eyes, baby's got blue eyes ..."
case "Red"
Response.Write "Red Red Wine ..."
case else
Response.Write "Jeez, I've never heard of that color before!"
end select

Introduction to ASP Ebook

Download this ebook to get everything you need to know about learning ASP - from a step by step tutorial to function lists, sample code, common errors and solutions, and much more! 101 pages.
This site needs an editor - click to learn more!

Add IF%2DTHEN+and+CASE+statements to Twitter Add IF%2DTHEN+and+CASE+statements to Facebook Add IF%2DTHEN+and+CASE+statements to MySpace Add IF%2DTHEN+and+CASE+statements to Del.icio.us Digg IF%2DTHEN+and+CASE+statements Add IF%2DTHEN+and+CASE+statements to Yahoo My Web Add IF%2DTHEN+and+CASE+statements to Google Bookmarks Add IF%2DTHEN+and+CASE+statements to Stumbleupon Add IF%2DTHEN+and+CASE+statements to Reddit




RSS | Related Articles | Editor's Picks Articles | Top Ten Articles | Previous Features | Site Map


For FREE email updates, subscribe to the ASP Newsletter


Past Issues


print
Printer Friendly
bookmark
Bookmark
tell friend
Tell a Friend
forum
Forum
email
Email Editor


Content copyright © 2014 by Lisa Shea. All rights reserved.
This content was written by Lisa Shea. If you wish to use this content in any manner, you need written permission. Contact BellaOnline Administration for details.

g


g features
Best uses for RSS

RSS and its future.

Force Download Dialog box with ASP

Archives | Site Map

forum
Forum
email
Contact

Past Issues
memberscenter


vote
Poetry
Daily
Weekly
Monthly
Less than Monthly



BellaOnline on Facebook
g


| About BellaOnline | Privacy Policy | Advertising | Become an Editor |
Website copyright © 2014 Minerva WebWorks LLC. All rights reserved.


BellaOnline Editor