By “FlyingBono” 2009_02By FlyingBono
ASP code is embedded in HTML using tags. A ASP scripting block always starts with. Server scripts are executed on the server, and can c ontain any expressions, statements, procedures, or operators valid for the scripting language you prefer to use. Format 2009_02By FlyingBono
response.write : used to write output to a browser The following example sends the text "Hello A SP" to the browser. View the Output Page 2009_02By FlyingBono
Variable Assigning values in ASP is straightforward enough, just use the equals "=" operator. If the variable is declared outside a procedure it can be changed by any script in the ASP file. If the variable is declared inside a pr ocedure, it is created and destroyed every time the procedure is executed. Can use without declaring variables Option Explicit statement ▪ Used to force explicit declaration of all variables in that script Format Dim Variable Example Dim strName 2009_02By FlyingBono
The Rule of Variables Variable name must start with an alphabetic character Variables must not start with a number. Variables cannot contain a period, special characters. Variables can contain letters, _, and numbers. Variables cannot be longer than 255 characters AvailablestrName, strName123, strName_123, _strName Disavailablestr!Name, 123strName, strName~123, ~strNam 2009_02By FlyingBono
Const The const keyword is used to create a read only variable. Once initialized, the value of the variable cannot be chang ed but can be used just like any other variable. Format Const const_name = value Example Const MaxNumber = _02By FlyingBono
Data types in ASP Just one data type called variant ▪ This special data type can act like any type that you can create as well as an object data type. ▪ When you place a value in a variant data type, it decides for you how the value should be stored. 2009_02By FlyingBono
Number type TypeRange Integer Integer from -32,768 to 32,767 Long Integer from -2,147,483,684 to 2,147,483,647 Byte Integer 0 to 255 Single Negative number from E38 to E-45 Double Negative number from E308 to E- 324 Currency -922,337,203,685, ∼ 922,337,203,685, _02By FlyingBono
Character type Date type Boolean type Store a value of ‘True’ or ‘False’ Automatically, change the value as ‘-1’ or ‘0’ FormatVariable_name = “characters” ExamplestrName = “Mr.Kim” FormatVariable_name = # date # ExamplestrTime = # 04/01/2009 # 2009_02By FlyingBono
This example demonstrates How to declare a variable How to assign a value to it How to use the value in a text View the Output Page 2009_02By FlyingBono
Arithmetic operators Comparison operators OperatorDescription =Equal To <Less Than >Greater Than <=Less Than Or Equal To >=Greater Than Or Equal To <>Not Equal To OperatorEnglish +Addition -Subtraction *Multiplication /Division ^Exponential ModModulus -Negation \Integer Division 2009_02By FlyingBono
Logical operators String operator OperatorDescription AND Both Must be T RUE OR One Must be TR UE NOT Flips Truth Valu e XOR One or the othe r but not both OperatorDescription &String Concatenation 2009_02By FlyingBono
Comments are skipped by the compiler. Using for denoting comment in HTML Using ‘(single-quote) for denoting comment in ASP Once starting a line as a comment, the whole line must be a comment. 2009_02By FlyingBono
View the Output Page 2009_02By FlyingBono
A data structure consisting of a group of elements that are accessed by indexing. Type of Arrays Fixed-sized arrays (static arrays) Dynamic arrays Multi-dimensional arrays 2009_02By FlyingBono
Fixed-sized arrays (static arrays) These size cannot change once their storage has been allocated. Using a Dim keyword for declaration like variables ‘( num )’ is used to set array sizes Format Dim Array_name (number) Example Dim strMember(2) 2009_02By FlyingBono
Dynamic arrays These arrays can be resized. Using a Dim keyword for declaration like variables ‘()’ is used to declare arrays Using a ReDim keyword for allocating or reallocating storage space Format Dim Array_name () ReDim Array_name(number) Example Dim strMember() ReDim strMember1(3) 2009_02By FlyingBono
Multi-dimensional arrays An array that contains at least one other array as the value of one of the indexes Using a Dim keyword for declaration like variables ‘( num, num )’ is used to set array sizes Format Dim Array_name (number, number) Example Dim strMember(2, 2) 2009_02By FlyingBono
View the Output Page 2009_02By FlyingBono
If Else Can execute a set of code depending on a condition Format If condition then statement1, code to be executed if condition is true Else statement2, code to be executed if condition is false End If Example If intScore = 1 Then Response.Write “You are a member." Else Response.Write “You are not a member." End If 2009_02By FlyingBono
at times you will want to check for multiple conditions, using a ElseIf Format If condition1 then statement1 ElseIf condition2 then statement2 Else statement3 End If Example If intScore = 1 Then Response.Write “You are a member." Elseif intScore = 2 then Response.Write “You are not a member." Else Response.Write “Goodbye.” End If 2009_02By FlyingBono
View the Output Page 2009_02By FlyingBono
Select Case Checking for multiple is equ al to conditions of a variable Case Else ▪ This case is actually a catch all option for every case that does not fit into the defined cases. ▪ In other words, if all these case s don't match then using the "C ase Else" Format Select Case Condition Case value1 Statement1 Case value2 Statement2 Case Else Statement3 End Select Example Select Case strScore Case “Gold” Response.Write “Gold” Case “Silver” Response.Write “Oops” Case Else Response.Write “Bye” End Select 2009_02By FlyingBono
View the Output Page 2009_02By FlyingBono
For Loop A For Loop is used for special situations when you need to do something over and over again until some condition statement fails. Format For Initial To Max Step Increasement Statement Next Example For i = 1 To 10 Step 1 Response.Write “Your visit number is” & I & " " Next 2009_02By FlyingBono
For Each Loop For Each Loop is useful when you want to go through every element in an array, but you do not know how many elements there are inside the array. Format For Each element In array Statement Next Example For Each strItem In strBuy Response.Write strItem & " " Next 2009_02By FlyingBono
View the Output Page 2009_02By FlyingBono
Do Loop The Do Loop structure repeats a block of statements until a specified condition is met. There are three types of Do Loop, Do Until, and Do While. Format 1 Do While condition Statement Loop Example Do While intCount < 10 Response.Write “number : " & intCount “ " intCount = intCount + 1 Loop 2009_02By FlyingBono
Format 3 Do Until condition Statement Loop Example Do Until counter=0 Response.Write("The counter is: "&counter&" ") counter=counter-1 loop Format 2 Do Statement Loop condition Example Do Response.Write("The counter is: "&counter&" ") counter=counter-1 loop until counter =0 2009_02By FlyingBono
View the Output Page 2009_02By FlyingBono
A procedure is a specified series of actions, acts or operations which have to be executed in the same manner. Sub Procedures Function 2009_02By FlyingBono
Sub Procedures ASP Sub Procedures are a collection of ASP statements that perform a task, and are executed by an event procedure. Event Procedures are any clickable objects, or onload event. Sub procedures do not return a value, but executes it's content on "call". 2009_02By FlyingBono
Format Sub procedure_name() Statement End Sub Sub procedure_name(argument) Statement End Sub Example Sub GetInfo() dim name,telephone,fee name="Mr. John Doe" phone=“0251" fee=20 Response.write("Name: "& name &" ") Response.write(“Phone: "& phone &" ") Response.write("Fee: "& fee &" ") End Sub GetInfo() Sub circle(r) dim pi,area,diameter,circum pi=3.14 area=pi*r^2 diameter=2*r circum=2*pi*r Response.write("The radius of Circle "&r&" has the area of: "&area) Response.write(", the diameter of: "&diameter&" and a circumference of: "&circum) End Sub 2009_02By FlyingBono
View the Output Page 2009_02By FlyingBono
Functions Function procedures are similar to a 'Sub procedure', but can also return a value. Format Function function_name() Statement End Function Function function_name(argument) Statement End Function Example Function userName() userName = "MaryLou" End Function Function total(price) dim tax tax=price*.09 total=price + tax End Function 2009_02By FlyingBono
View the Output Page 2009_02By FlyingBono