Last time round we stopped with just on printing output with asp.It means that you can print html tags and html content using ASP the same way PHP or JSP does.
Now we will see some commonly used variable declarations and loop constructs in ASP.
Variables
People who have worked in Visual Basic will have come accross the Dim keyword. Its the same way variables are declared in ASP.
[code lang=”asp”]
<%
dim variablename
variablename="value"
response.write("value is: " & variablename)
%>
[/code]
As you can see, the Ampersand operator is used for appending.
Arrays
You can declare and use arrays in the following manner. We will see how to use loops so that you can access the array elements
[code lang=”asp”]
<%
Dim array_name(array_size)
array_name(1) = "value 1"
array_name(2) = "value 2"
array_name(3) = "value 3"
array_name(4) = "value 4"
array_name(5) = "value 5"
array_name(6) = "value 6"
%>
[/code]
For Next Loop
This is the general for loop you might have used in some application.
[code lang=”asp”]
Dim variable
for variable=start to end [optional step argument]
statements
next
[/code]
The step argument is used to increment the variable in steps less than or more than 1
Do Loops
[code lang=”asp”]
<%
Dim variable
variable=5
Do
response.write("The variable is: "&variable&"
")
variable=variable-1
loop until variable=0
%>
[/code]
IF statements
[code lang=”asp”]
<%
if condition is true then
true statement
else
false statement
end if
%>
[/code]
Select Case
[code lang=”asp”]
Select Case variable
case 1
response.write(“case 1”)
case 2
response.write(“case 2”)
case 3
response.write(“case 3”)
end select
[/code]
We will see about Functions and Procedures in the next part.