Download presentation
Presentation is loading. Please wait.
1
Basic Scripting in VBScript VBScript must enclosed by No HTML code is allowed inside a VBScript code block Nested scripting block is not allowed Spaces within a scripting block are ignored A VBScript code can be placed in any where in an ASP VB style comments are permitted
2
VBScript Variables VBScript variables follows the same naming rules as other programming language (e.g, C++) Begin with an alphabetic character Case insensitive Variables are not typed (variants) The type of a variable depends on its value All types are treated the same myVariable = 12.34 myVariable = “Hello World” myVariable = True myVariable = False
3
Types Supported inVBScript Numeric types Integer, byte, long, single, double Strings, Date, Boolean (true or false) TypeName() function Returns the type name of a variant myVariable = “Hello World” IF typeName(myVariable) = “String” THEN … Type constants Compare the type of a variable myVariable = “Hello World” IF myVariable = VbString THEN …
4
Variable Scopes Local variables Variables declared inside a function or procedure Global variables Variables declared outside of functions/procedures The scope of a global variable is within the page Dim var1, var2 var1 = 123 ‘global variable Sub myProcedure() var1 = “Hello World” ‘local variable
5
Arrays Array size must been declared Redim can be used to change array size Array index starts from 0 Dim arrayA(29) ‘an array with 30 elements FOR i = 0 TO 29 arrayA(i) = “testing” NEXT VBScript supports multi-dimension arrays Dim arrayB(4, 4) ‘an two dimensional array arrayB(0, 0) = “hello”
6
ASP Object Model Standard objects: Application object - application session management Request object - retrieve client data Response object - send output to browsers Session object - client session management Standard components: Ad Rotator - automatic rotating AD’s Page Counter component Database access component File access component
7
Request Object
8
QueryString Object Retrieve data submitted through URL parameters http://www.dit.ie/cgibin/listClass.asp?classID=dt2663 Form fields submitted using the “GET” method QueryString object usage request.queryString(“classID”) returns “dt2663” request.queryString returns a collection of namevalue pairs <% for each qsName in request.queryString response.write(qsName) next %>
9
QueryString Element Count Request.queryString(a-name).Count Returns the number of values of a name itemNo=JK100,JK231,JK681 request.queryString(itemNo).count ---> 3 Used for multi-valued name value pairs Multiple checkboxes Multiple selected items in a dropdown list Any form fields with multiple values
10
QueryString Example <% for each qsName in request.queryString valNum = request.queryString(qsName).count response.write(qsName & "=") if valNum = 1 then val = request.queryString(qsName) response.write(val) else for i = 1 to valNum val = request.queryString(qsName)(i) response.write(val & ",") next end if response.write(" ") next %>
11
Form Object Allows to access form submission data The methods are similar to that of queryString <% for each formField in request.form valNum = request. form(formField).count response.write(formField & "=") if valNum = 1 then val = request. form(formField) response.write(val) else for i = 1 to valNum val = request. form(formField)(i) response.write(val & ",") next end if response.write(" ") Next %>
12
Response Object Generate HTML output for web browsers Response.write() is used in a scripting block to produce output response.write(request.queryString(qsName)) is a short cut for request.write() function <% myVariable = “Hello” youVariable = “World” response.write(myVariable & “ “ & youVariable) %>
13
Response Object Properties/Methods Response.buffer Set it on (true) or off (false) response.flush() - sends bufferred output & continue script processing response.clear() - erase bufferred contents response.end() - sends buffered output & stop script processing Response.expires = minutes When cached pages should expire in web browsers Response.expiresAbsoluate = date/time When cached pages expire in web browsers Response.redirection = URL Branch off to the specified web page
14
Summary ASP Architecture ASP object model Basic VBScript scripting techniques VBScript control structures Request object Response object
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.