Home

Variables  hold string or numeric data. Functions and subroutines are block of codes that you can call to execute by their name. In general the difference between a function and sub is that the function can return a value. Both function and subroutine can take input values, as shown in the makedouble() function in the example below.

Variables , functions and displaying data.

In this example we will use the basic HTML page, from the previous example and test.

You can run asp code from anywhere within an html page, provided that the page is saved as a .asp page on the server. Asp code blocks are written within <%%> tags. So wathever is written between <%%> tag is executed on the server and it will show some output if you say so. There are two ways to display something to the browser from asp. Either use response.write "mydata" or use the <%="mydata"%> tag. In both cases I am outputting a string value.

First we will declare a variable named i. Then we will assign a value 2 to the variable.

I have written two functions and a subroutine. The subroutine named MySub is using one method of sending data to the browser. Along with the string data, the response.write method is also writing a line break <br>.

Then I am calling Now(), which is a built in function that returns the current system time and date. Asp comes with many subroutines and function, check the manual to find them all.

Comments

In asp comments are written after '. Look at line number two: 'This is a comment.

<%
'This is a comment.
Dim i
i=2

Function myFunction()
 Dim j, k
 j=5
 k=4
 myFunction = j + k
End Function

Sub MySub()
 response.write "I am doing something.<br>"
End Sub

Function MakeDouble(md)
  MakeDouble=md+md
End Function
%>


<html>

<head>
<meta
http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>
This is my page about something.</title>

</head>

<body>

<b>
Heading of my page:</b>

<br>

<font
size=2 face=arial>
The value of i is: <%=i%><br>

My age is: <%=myFunction()%>.<br>
<br>
Calling the subroutine: <%MySub()%><br>
<br>
Function to double a number: <%=MakeDouble(50)%><br>
<br>
Another example of double: <%=10 + MakeDouble(5)%><br>
<br>
System Date and time is: <%=
Now()%><br>
<br>
This is another way to write data:
<%
Response.write
Now
%>
<br>

</font>

</body>
</html>

 

[Download Sample Code]