ASP Tutorial Lesson 6: Decisions

Making decisions is a key part of the function of a script. The two main methods in ASP are “IF” and “Case”.

IF

What we are talking about here is basically “If this condition is true then do this”. The syntax is very close to this.

IF 10 > 5 THEN
response.write(“10 is more than 5”)
END IF

The condition in the above statement is the maths bit (“10 > 5”) but could just as easily be

IF name = “fred” THEN ..

These conditions have to evaluate to true, so if you want to know if something is not true then you can use “not”, as in the following example.

IF NOT name = “fred” THEN ..

Sometimes you want to do something if the condition is true and something else otherwise. We can use “ELSE” to do this.

IF this = true THEN
DoThis()
ELSE
DoTheOtherThing()
END IF

Multiple Choice

There is a little more we can discuss with IF but the above will give you enough flexibility for now. Another important decision making facility in ASP is the SELECT CASE.This takes a number of options a value could match plus has an ELSE to allow you to catch all other possibilities.

SELECT CASE value
CASE “this”
doThis()
CASE “that”
doThat()
CASE ELSE
doTheOther()
END SELECT