NETB131 Programming Project
Programming language ASP
An overview

Boris Stoyanov Todorov, F38692

1. History and Special Features
Look around you. No really, look around you. In the past 30 years, computers have taken over from the filing cabinets of the world to become the (almost) universal way people store and look up information. Would you rather spend five minutes rifling through some badly organized stack of paper for the name of a client or the price of a book, or spend ten seconds typing in a search query on a computer and getting the desired information back immediately? I thought so—the computer wins every time.
When microsoft released the .NET Framework 1.0 Technology Preview in July 2000, it was immediately clear that Web development was going to change. The company's then-current technology, Active Server Pages 3.0 (ASP), was powerful and flexible, and it made the creation of dynamic Web sites easy. ASP spawned a whole series of books, articles, Web sites, and components, all to make the development process even easier. What ASP didn't have, however, was an application framework; it was never an enterprise development tool. Everything you did in ASP was code orientedyou just couldn't get away with not writing code. ASP.NET was designed to counter this problem. One of its key design goals was to make programming easier and quicker by reducing the amount of code you have to create. Enter the declarative programming model, a rich server control hierarchy with events, a large class library, and support for development tools from the humble Notepad to the high-end Visual Studio .NET. All in all, ASP.NET was a huge leap forward. Now, with the release of version 2.0, we've seen another giant step towards increased developer productivity. The feature set of ASP.NET has increased, with more server controls and APIs wrapping functionality, reducing the amount of code you need to write.
It’s not just in the office that data-driven Web sites have proven popular. Server-side technologies now allow people to hook electronic data sources—databases, spreadsheets, Extensible Markup Language (XML) files, Windows services, and more—to Web sites. This means that today’s World Wide Web is a place of dynamic, data-driven Web sites, rather than the collections of static Hypertext Markup Language (HTML) pages it once was. Regardless of whether you develop your Web sites with Active Server Pages (ASP), ASP.NET, PHP, JavaServer Pages (JSP), or one of numerous other technologies, you can use a data source to interact with your users.

2. "Hello World" Program

3.Fundamental Data Types
Declaring a Variable in ASP
It is a good programming practice to declare all your variables before you use them, even though it is not required. Nearly all programming languages require you to declare variables and doing so also increases your program's readability. In ASP you declare a variable with the use of the Dim keyword, which is short for Dimension. Dimension in english refers to the amount of space something takes up in the real world, but in computer terms it refers to space in computer memory. Variables can be declared one at a time or all at once. Below is an example of both methods.
ASP Code:
'Single Variable Declarations
Dim myVar1
Dim myVar2
'Multiple Variable Declarations
Dim myVar6, myVar7, myVar8
%>

ASP Variable Naming Conventions
Once again, ASP uses VBScript by default and so it also uses VBScripts variable naming conventions. These rules are:
1.Variable name must start with an alphabetic character (A through Z or a through z)
2.Variables cannot contain a period
3.Variables cannot be longer than 255 characters (don't think that'll be a problem!)
4.Variables must be unique in the scope in which it is declared (Basically, don't declare the same variable name in one script and you will be OK).
ASP - Assigning Values to ASP Variables
Assigning values in ASP is straightforward enough, just use the equals "=" operator. Below we have set a variable equal to a number and a separate variable equal to a string.
ASP Code:
'Single Variable Declarations
Dim myString, myNum, myGarbage
myNum = 25
myString = "Hello"
myGarbage = 99
myGarbage = "I changed my variable"

Response.Write("myNum = " & myNum & "
") Response.Write("myString = " & myString & "
")
Response.Write("myGarbage = " & myGarbage & "
")
%>

Output:
myNum = 25 myString = Hello
myGarbage = I changed my variable
4. Basic Control Flow
If Statement Syntax
ASP's If Statement is slightly different than the If Statement implementation in most other languages. There are no brackets, or curly braces, nor are there any parenthesis. Rather the beginning of the code to be executed in the If Statement when its true is marked with Then and the end of the If Statement is plainly marked with End If. Below is a very basic If Statement that will always be True.
ASP Code:
Dim myNum
myNum = 6
If myNum = 6 Then
Response.Write("Variable myNum = 6")
End If
%>

Output:
Variable myNum = 6
You might notice that the "=" operator is used to both set the value of myNum to 6 at first, then it is used to compare myNum to 6 in our If Statement. This dual use of the equals operator is confusing to many, but it might help you to remember that in ASP you cannot set the value of variables within If Statements, which means that the "=" can only compare!
If Else Conditional Statement
Sometimes you might want to execute some code both when the If Statement is True and some different code when it is False. Just like other programming languages, you can do this in ASP with the use of the Else keyword. Below is an example that will always be false, so that the Else portion of the If Statement is always executed.
ASP Code:
Dim myNum
myNum = 23
If myNum = 6 Then
Response.Write("Variable myNum = 6")
Else
Response.Write("**Variable myNum = " & myNum)
End If
%>

Output:
**Variable myNum = 23
For Statement
ASP Code:
Dim n = document.getElementById('value').value
Dim sum = 0
For i = 1 To n
sum=sum+i*i
Next
Response.Write "sum"
%>

Output:
sum of 1*1+2*2+3*3+...+n*n

The For Statement uses a variable to keep track of repetitions. In this example, i is set to 5 initially. The computer executes all the statements between the For line and the Next line each time it goes through the loop. When it gets to the end, it goes back to the For line and adds 1 to the variable. It continues in this way until the variable reaches the end value - in this case 16. Execution then continues with the line after the Next statement.
5. Functions
Functions and procedures provide a way to create re-usable modules of programming code and avoid repeating the same block of code every time you do the same task. The ASP pages are executed from top to bottom and if you don't have any functions/procedures in your ASP page, the ASP parsing engine simply processes your entire file from the beginning to the end. ASP functions and procedures, on the other hand, are executed only when called, from within the ASP code (they might be called from another function/procedure or directly from inline code). has 2 types of functions. The ones returning a value start with Function keyword and end with End Function . The second type of function in VBScript doesn’t return a value starts with the Sub keyword and ends with End Sub , defining the function as a subroutine.
ASP Code:
Function MultNum(iNum1, iNum2)
MultNum = iNum1 * iNum2
End Function
%>

The function above gets 2 arguments and returns them multiplied. VBScript functions can be without arguments or they can have 1 or more arguments.
To return a value from a function, just assign this value to the name of the function:
MultNum = iNum1 * iNum2
To use a Funtion in ASP write name of that function and in brackets put the variables. In our example MultNum(iNum1, iNum2)
Subroutines don’t return value.
ASP Code:
Sub ShowNumber(iNumber)
MsgBox(iNumber)
End Sub
%>

The subroutine above just outputs the number passed as an argument in a message box.
6. Arrays
Arrays in ASP follow the exact same form and rules as those arrays in VBScript. You can create an Arrays of specific size or you can create a dynamic sized array. Below we have examples of both types of arrays.
ASP Code:
Dim myFixedArray(3) 'Fixed size array
Dim myDynArray() 'Dynamic size array
%>

Assigning Values to an Array
Let's fill up our fixed size array with values. Our fixed array is going to store the names of famous people. To assign a value to an array you need to know three things:
1.The name of the array
2.The value you want to store
3.The position in the array where you want to store the value.
An array is a group of variables that you can access by specifying the position inside the array. Our array myFixedArray has four positions: 0, 1, 2 and 3. Let's assign some values to our array.
ASP Code:
Dim myFixedArray(3) 'Fixed size array
myFixedArray(0) = "Albert Einstein"
myFixedArray(1) = "Mother Teresa"
myFixedArray(2) = "Bill Gates"
myFixedArray(3) = "Martin Luther King Jr."
%>

ASP Dynamic Sized Arrays
To create an array whose size can be changed at any time simply do not put a number within the parenthesis when you declare the array. When you know what size you want the array to be use the ReDim keyword. You may ReDim as many times as you wish. If you want to keep your data that already exists in the array then use the Preserve keyword. Below is an example of all these things we have just talked about.
ASP Code:
Dim myDynArray() 'Dynamic size array
ReDim myDynArray(1)
myDynArray(0) = "Albert Einstein"
myDynArray(1) = "Mother Teresa"
ReDim Preserve myDynArray(3)
myDynArray(2) = "Bill Gates"
myDynArray(3) = "Martin Luther King Jr."
For Each item In myDynArray
Response.Write(item & "
")
Next
%>

Output:
Albert Einstein Mother Teresa Bill Gates Martin Luther King Jr.
7. Compilers
8. Projects and Software in ASP


9. Standard

10. References