Padding Padding
Janet
Systems
 Register  Login 
Telephone  01628 566 178
Website Design, Hosting and Software Services
  Search 
Padding
corner Padding corner
Padding Padding
corner Padding corner
 ASP Articles

The if then ... else ... end if statement is one of the core statements used in ASP. Using this statement we can test if a condition is met, then dependant upon the result make one of two actions. As an example we will show a greeting on the page if its the morning.

<%
If time < 12:00 then
%>
Good morning, welcome to ...
<%
End If
%>

The format used in our example above, is used to execute a block of code which extends over more than one line.  If we only have a single statement to execute we can make it more efficient, by putting the whole statement on one line and omitting the End IF.

<%
If time < 12:00 then response.write("Good morning, welcome to ...")
%>

To help you in debugging your program, it is worth adding a comment after the End If so you know which If block it relates to.

The If statement may be further extended so that if the condition is met we do one action, otherwise we will do another.  We do this using the Else statement.

<%
If time < 12:00 then
%>
Good morning, welcome to ...
<%
Else 'time < 12:00
%>
Good afternoon, welcome to ...
<%
End If 'time < 12:00
%>


This article viewed: 2028 times Back

Copyright © 2004-2007 Janet Systems Ltd.

 Print   

DotNetNuke Website design and hosting from £15.00 per month. More...

Looking for a website design company in the Thames Valley, call us on 01628 566178

DotNetNuke Modules
DotNetNuke Modules availalble from Janet Systems

DotNetNuke Skins
DotNetNukeSkins.gif

from Janet Systems

Padding
Copyright 2002-2008 Janet Systems Ltd.   Terms Of Use  Privacy Statement Tuesday, May 13, 2008