KidsLovePC Contact Us
  Home   PHP  Graphics ASP  JavaScript   J2EE  HTML  JAVA   Swing   Webtip  Forums  Lyric  Free sheet music  Ringtones

Scripting Objects

The vbScript library that provides the scripting language support for AS Pals provides a number of other objects that can be used to extend the developer's application. These are collectively known as Scripting Objects. The three objects we will be concerned with are:

Dictionary Object -- Allows the programmer to store information in a single data structure similiar to a collection

FileSystemObject -- Provides utilities to locate, open, read and close files on the server.

TextStream -- This objects allows you to manipulate the contents of files.

Dictionary object

A dictionary object can be thought of a s a Webster's dictionary for your application where you can store information in it, such as descriptions and attach a keyword so that you can later locate the information.

Creating Dictionary objects

We may create an instance of dictionary object like following:


'In VBScript
Dim objMyDictionary
objMyDictionary = Server.CreateObject("Scripting.Dictionary")

//In JScript:
var objMyDictionary = Server.CreateObject('Scripting.Dictionary');

Dictionary object methods

Add(key,item): Adds the key/item to the dictionary
Exists(key): Returns True if the specified key exists or False if not.
Items(): Returns an array containing all the items in a Dictionary object.
Keys(): Returns an array containing all the keys in a Dictionary object.
Remove(key): Removes a single key/item pair specified by key.
RemoveAll): removes all the key/item pairs.

Dictionary Object properties:

CompareMode: (VBScript only). Sets or returns the string comparison mode for the keys.
Count: Read only. Returns the number of key/tiem pairs in the Dictionary.
Item(key): Sets or returns the value of the item for the specified key.
Key(key): Sets the value of key.

Adding and removing items

Once we create an instance of dictioanry, we can add items to it, retrieve them and remove them

'In VBScript
objMyDictionary.Add "MyKey","MyItem" 'Add value MyItem with key Mykey
objMyDictionary.Add "MyKey2","MyItem2" 'Add value MyItem2 with key Mykey2
blnIsThere = objMyDictionary.Exists("MyKey") ' Return true bacause the item exists;
strItem = objMyDictionary.Item("MyKey2") 'Retrieve value of Mykey2
strItem= objMyDictionary.Remove("MyKEy") 'Retrieve and remove MYkey
objMyData.removeAll ' Remove All the Items

//In JScript
objMyDictionary.Add 'MyKey','MyItem' //Add value MyItem with key Mykey
objMyDictionary.Add 'MyKey2',"MyItem2' //Add value MyItem2 with key Mykey2
blnIsThere = objMyDictionary.Exists('MyKey') // Return true bacause the item exists;
strItem = objMyDictionary.Item('MyKey2') //Retrieve value of Mykey2
strItem= objMyDictionary.Remove('MyKEy') //Retrieve and remove MYkey
objMyData.removeAll // Remove All the Items

 

 

Example 1 -- Save information about an Apple, Lemon and Cherry, the color of each

<%
dim objDictionary

Set objDictionary=CreateObject("Scripting.Dictionary")
objDictionary.add "Apple","red"
objDictionary.add "Lemon","Yellow"
'Use hte Add method to add more items to the dictionary
'Syntax: object.add key, value
dim strKey
dim strValue
strKey="Cherry"
strValue="Red"
objDictionary.Add strKey,strValue

'Retrieve Data

Response.write " Retrieving Data..<br>"

strValue=objDictionary.Item("Apple")
Response.write "Value stored with the key of 'Apple'is " & strValue

'Use the Item method to locate items in the dictionary
strKey = "Lemon"
strValue = objDictionary.Item(strKey)
Response.Write "Value Stored with key of '" &strKey& "' is " & strValue
Response.write "Store dictionary for later use<br>"
Set Session("MyDictionary") = objDictionary
Session("MyDictionaryStored") = True
Response.Write "Dictionary is stored in your session object."
%>

Example 2-- Changing information in the dictionary

<%
Dim bDictionaryExists
bDictionaryExists = Session ("MyDictionaryStored")

if bDictionaryExists <> true then
Response.Redirect "dic.asp"
else
dim objDictionary
Set objDictionary = Session("MyDictionary")

'Use the Exists property to determine if the Item exists. If so, change 'it's value

if objDictionary.Exists("Apple") then
objDictionary.Item("Apple") = "Green"
Response.write " Changed the value of Apple to Green<br>"
Response.write "Value stored with key of 'Apple' is " & objDictionary.Item("Apple") & "<br>"
end if

if objDictionary.Exists("Lemon") then
objDictionary.Key("Lemon")= "Banana"
Response.write "Change the key of Lemon to banana"
Response.write "Value stored with key of 'Banana' is " & objdictionary.Item("Banana") & "<br>"

end if
end if
%>

 
ASP tutorial
What is ASP
Install IIS
VBScript or JScript
ClientSide vs ServerSide scripting
ASP execution order
Dealing with Form
More Form example
Variable &Variant
String
Local variable
Global variable
Arrays
Use if_then_else
Use Select Case
For_Next loop
Do_while loop
Subroutine vs Function
Request Object
QueryString
Count Keyword
Using QueryString
Application, Method, Events
Create Virtual Directory
Save array in Application
Session, Method, Events
Using Cookie
Server Object
Ad Rotator
Content Linker
Browser
Dictionary object
Filesystemobject Object

 

 

 

Best books about ASP & ASP.Net from Amazon
Beginning Dynamic Websites : with ASP.NET Web Matrix (Programmer to Programmer) (Paperback) Build Your Own ASP.NET Website Using C# & VB.NET (Build Your Own) (Paperback) Professional Active Server Pages 3.0 (Programmer to Programmer) (Paperback) ASP.NET Cookbook (Paperback) ASP.NET Kick Start (Paperback)

 

Printer Inkjet A Z lyricsLearn ChineseHome|PHP|Swing|HTML|JavaScript|ASP|JAVA|Forum|WebTip|Contact Us
Copyright © kidslovepc.com All rights reserved(new). Privacy|Copyright
designed by info@kidslovepc.com

Please help us cover the web site maintenance fee.
barcode scanner Thermal Printer credit card machine bar code printer