Download presentation
Presentation is loading. Please wait.
Published byJeffry Bennett Modified over 8 years ago
1
By “FlyingBono” 2009_02By FlyingBono
2
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
3
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
4
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
5
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
6
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 = 23064434 2009_02By FlyingBono
7
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
8
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 -3.402823E38 to -1.401298E-45 Double Negative number from -1.79769313486232E308 to -4.94065645841247E- 324 Currency -922,337,203,685,477.5808 ∼ 922,337,203,685,488.5807 2009_02By FlyingBono
9
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
10
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
11
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
12
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
13
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
14
View the Output Page 2009_02By FlyingBono
15
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
16
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
17
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
18
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
19
View the Output Page 2009_02By FlyingBono
20
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
21
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
22
View the Output Page 2009_02By FlyingBono
23
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
24
View the Output Page 2009_02By FlyingBono
25
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
26
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
27
View the Output Page 2009_02By FlyingBono
28
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
29
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
30
View the Output Page 2009_02By FlyingBono
31
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
32
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
33
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
34
View the Output Page 2009_02By FlyingBono
35
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
36
View the Output Page 2009_02By FlyingBono
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.