Senin, 09 Februari 2009

ASP Tutorial
Part 3 - IF Statements


Introduction

Over the past two parts I have shown you the basics of text in ASP and how to store it as variables. In this part of the tutorial I will show you how to use IF statements to make decisions in your scripts.

The Basics Of IF

If statements are used to compare two values and carry out different actions based on the results of the test. If statements take the form IF, THEN, ELSE. Basically the IF part checks for a condition. If it is true, the then statement is executed. If not, the else statement is executed.

IF Strucure

The structure of an IF statement is as follows:

If something=somethingelse Then
Execute some code
Else
Execute other code
End If


Common Comparisions

The ASP IF statement construction is very much like plain text, but here is a quick example of a common use of ASP. In this example the user has entered a password which has been stored in the variable EnteredPassword. The idea of this script it to check whether the user has entered the correct password:

<%@ Language=VBScript %>
<%
If EnteredPassword="password1" Then
Response.Write("Well done. You got the password right.")
Else
Response.Write("Sorry. That was the wrong password.")
End If
%>

If the user enters the correct password (password1) the text:

Well done. You got password right.

but if you get it incorrect you will be shown the text:

Sorry. That was the wrong password.


Other IF Options

There are many of different comparisions you can make with ASP, for example you can comapre two variables:

If EnteredPassword=RealPassword Then

or different types of comparison:

If Age>13 Then

which will check to see if the age entered by the user is greater than 13.

You can also place HTML etc. in IF statements, as the ASP will continue executing a THEN statement until it reaches an Else or an End If, and will continue to execute Else statements until it reaches End If, for example:

<%
If EnteredPassword="password1" Then
%>
Congratulations. You may enter.
<%
Else
%>
ERROR! You cannot enter.
<%
End If
%>


Part 4

Now you can output text, place text and numbers in variables and execute conditional statements. In the next part I will show you how to operate loops to repeat sections of code.



More ASP Sites
Related Reading


source : http://www.freewebmasterhelp.com


--------------------------------------------


Related :

TransferringFiles
UsingCrystalReports6
VerifyUserEmailAddressPHP-1
VerifyUserEmailAddressPHP-2
viewinformationvb2005
WatermarkImagesFlyPHP-1
WatermarkImagesFlyPHP-2
WhatAretheIssues
What-isMySQL
WhatSQLServerExpress
writefileinvb2005
WritingFileDialogBox