If...then...Else

by Tim Warke
TtotalASP.co.uk
Thursday, 28th July 2005

The If statement in visual basic script is most useful and basically essential if you want to do any sort of ASP programming. So in this tutorial we will simply outline the basic syntax and give a few examples of how it works.

The basic statement is as follows (assuming that foobar is an ASP variable you have defined):

<%
If foobar="yes" then
response.write "YES!"
Else
response.write "NOT YES!"
End if
%>

Easy to follow? There is a one line simpler version even if you leave out the Else part:

<%
If foobar="yes" then response.write "YES!"
%>

You can expand it to deal with other possibilities too:

<%
If foobar="yes" then
response.write "YES!"
Elseif foobar="no" then
response.write "NO!"
Elseif foobar="maybe" then
response.write "MAYBE!"
Else
response.write "NONE OF THE ABOVE!"
End if
%>

Again, the above should be fairly easy to follow, it works its way through the alternatives in the ELSEIF parts. If none of them are the case, then the ELSE alternative is outputted.

You can make your statements more complex too:

<%
If foobar="yes" and barfoo="no" then
response.write "FOOBAR YES, BARFOO NO"
End if
%>

I hope this has helped you understand the basic syntax of If-then-Else statements and I am sure you can think of various applications for them that you could use in your web programming.


Options:
Printer Friendly

About The Author:

© Tim Warke

Developer Categories



Developer Tutorials
ASP
CGI & Perl
CSS
Flash
HTML
Java
JavaScript
MySQL
PHP
Python
XML

Developer Documentation

Developer Tools



Search our Developer Tutorials
  The DevSyndicate Network