Advanced Programming ASP 3.0 (19)
This book provides a series of sample documents can be used to test script run-time library of a variety of attributes.
This chapter, the default code page can be used to provide a series of links to the vbscript example. Some examples of jscript as effective. These examples Chapter05 directory stored in the corresponding subdirectory, the display interfaces as shown in Figure 5-2:
Figure 5-2 asp sample script run-time object page
To view the Dictionary object is running, click on the first page in the menu a link to open the page called show_dictionary.asp. This page shows provide us with the contents of the Dictionary object, allowing tests of its properties and methods. Screen shown in Figure 5-3:
Figure 5-3 Dictionary object properties and methods
1. Dictionary of the global.asa file
Dictionary object with the sample page document provided by one of global.asa. Create and fill it in advance of a session layer of the Dictionary object scope, so the content is not lost between page requests. In general (taking into account the scalability), this is not an ideal approach. In this example, we can see the properties and methods Dictionary effect.
If a server to download and install the examples, we must create a global.asa file on this virtual applications. Or its contents will be added to the default site's root folder of the global.asa file. In Chapter 3 describes how to use the wizard to create the virtual application. However, for this example, create a virtual application of the method is the simplest example in the Chapter05 folder Right-click dictionary subfolders, in the Properties dialog box of the Home Directory option card, click on Create button, as shown in Figure 5-4 show:
Figure 5-4 to create the virtual application
In the global.asa file, the code used to create a conversation <OBJECT> element layer Scripting.Dictionary scope of the object instance. Then Session_onStart event handler will use a series of values in the Add Method Add Dictionary and reference to the Dictionary object assigned to the ASP session variables MyDictionary:
<OBJECT ID = "objBookList" RUNAT = "SERVER" SCOPE = "SESSION"
PROGID = "Scripting.Dictionary">
<SCRIPT LANGUAGE="VBScript" RUNAT="SERVER">
Sub Session_onStart ()
objBookList.Add "2610", "Professional Active Server Pages 3.0"
objBookList.Add "2882", "Beginning ASP Components"
objBookList.Add "1797", "Professional ASP Techniques"
objBookList.Add "1835", "AD0 2.0 Programmer's Reference"
Set Session ( "MyDictionary") = objBookList
2. Dictionary sample page
In "Scripting.Dictionary Object" page, the top priority is to get a session layer of the Dictionary object scope reference. Note that this reference is an object variable, it is necessary to use the Set keyword in VBScript.
Then, check whether an object (this is a good habit), if not properly establish a global.asa file that contains a virtual application, check to see what went wrong. You will see our own message instead of ASP error message (but note that this operation must be shut down for the default error handling).
on error resume next 'turn off error handling to test if object exists
'retrieve Dictionary object from user's session
Set objMyData = Session ( "MyDictionary")
If IsObject (objMyData) Then 'found Dictionary object in Session
<P> <DIV CLASS="subhead"> Iterating the Dictionary with Arrays </ DIV>
arrKeysArray = objMyData.Keys' get all the keys into an array
arrItemsArray = objMyData.Items' get all the items into an array
For intLoop = 0 To objMyData.Count - 1 'iterate through the array
Response.Write "Key: <B>" & arrKeysArray (intLoop) & "</ B> Value: <B>" _
& ArrItemsArray (intLoop) & "</ B> <BR>"
... Other code and controls go here ...
'could not find Dictionary object in the session
Response.Write "Dictionary object not available in global.asa for session"
Displayed on the page list the contents of the Dictionary is to use the Dictionary Object Items Method Key and created two arrays, you can use the code in front of their traversal.
3. Dictionary page controls
In the Dictionary of the contents of the list is a series of HTML controls, Dictionary object can be used to set certain properties and the implementation of various methods. All of these controls in a <FORM>, its ACTION attribute value is the page, so the contents of the form to submit back to this page. In the previous sections using the example of the same technology.
In paragraph <FORM> to change the attributes or the implementation of a method is through a button (no title) achievable. Properties and methods used to value the Add button beside the text box or list box.
Button on the page for the first set of entries in Dictionary of the Key property. Here uses a drop-down list, you can select a Key value already exists. The following code to create a page within the control of the part. In order to fill the list, use another Dictionary object traversal techniques, namely the For Each ... Next statement. Code is as follows:
<FORM ACTION = "<% = Request.ServerVariables (" SCRIPT_NAME ")%>" METHOD = "POST">
<P> <DIV CLASS="subhead"> The Dictionary Properties </ DIV>
<INPUT TYPE="SUBMIT" NAME="cmdChangeKey" VALUE=" ">
Dictionary.Key ( "
<SELECT NAME="lstChangeKey" SIZE="1">
For Each objItem in objMyData
Response.Write "<OPTION>" & objItem
</ SELECT> ") ="
<INPUT TYPE="TEXT" NAME="txtChangeKey" SIZE="15" VALUE="New Key Name"> "
... Other controls go here ...
4. The use of the properties and methods Dictionary
In "Scription.Dictionary Object" page, click the entry to check and change the attributes of the Key button, as shown in Figure 5-5:
Figure 5-5 Use of the Key Properties Dictionary
The form submitted to the page again. The above page contains a script to check the button is clicked value. It Resquest.Form collection in the name of where to find the button to determine which button is clicked. If it is found that a value corresponds to cmdChangKey, from the list or text box corresponding to the value and change the Key attributes:
'look for a command sent from the FORM section buttons
If Len (Request.Form ( "cmdChangeKey")) Then
strKeyName = Request.Form ( "lstChangeKey") 'Existing key from list box
strNewKey = Request.Form ( "txtChangeKey") 'New key value from text box
objMyData.Key (strKeyName) = strNewKey 'Set key property of this item
Reload the page after the contents of Dictionary list to see the results, as shown in Figure 5-6:
Figure 5-6 the results page after heavy
The rest of the code page used to set the Item property of an entry, or the implementation of the method of Dictionary object. The following is the code these operations, each attribute code and demo Key code very similar. The results showed that each of the content in the Dictionary list:
If Len (Request.Form ( "cmdChangeItem")) Then
strKeyName = Request.Form ( "lstChangeItem") 'Existing key from list box
strNewValue = Request.Form ( "txtChangeItem") 'New item value from text box
objMyData.Item (strKeyName) = strNewValue 'Set the Item property
If Len (Request.Form ( "cmdAdd")) Then
strKeyName = Request.Form ( "txtAddKey") 'New key value from text box
strItemValue = Request.Form ( "txtAddItem") 'New item value from text box
objMyData.Add strKeyName, strItemValue 'Execute the Add method
If Len (Request.Form ( "cmdRemove")) Then
strKeyName = Request.Form ( "lstRemove") 'Existion key from list box
objMyData.Remove strKeyName 'Execute the Remove method
If Len (Request.Form ( "cmdRemoveAll")) Then
objMyData.RemoveAll 'Execute the RemoveAll method
For example, if you now click the Add method of the button, the contents of the list in the Dictionary will add a new entry, as shown in Figure 5-7:
Figure 5-7 to add a new method
The results shown in Figure 5-8:
Figure 5-8 Add the results of methods
Can test the page in this Dictionary object properties and methods, you will find what factors and circumstances in which the object can cause errors Dictionary. For example, try to use one that already exists with the same key entry to add a entry to see what the results will appear.
5.4 Scripting.FileSystemObject object
FileSystemObject object provides access to a computer file system, it allows us to operate in the code text files, folders and drives. It is the script run-time library provided by one of the servers within the ASP pages are VBScript and JScript effective. If the page extension. Hta (that they are part of HTA), which can also be used on the client in the IE 5. This section only discuss the ASP script on the server how to use the FileSystemObject object.
Hypertext Application (HTA) from the designated "trusted" page of the paragraph in <HEAD> page contains elements <HTA: APPLICATION>. For example:
<HTA:APPLICATION ID="objMyApp" APPLICATIONNAME="myApp">
These pages can use client-side script engine of some commonly used features, these features are FileSystemObject object and object TextStream. Hypertext applications on more information, please visit the Microsoft Workshop Web site.
Can use the following procedure to create a FileSystemObject object instance:
Set objMyFSO = Server.CreateObject ( "Scripting.FileSystemObject")
/ / In JScript:
var objMyFSO = Server.CreateObject ( 'Scripting.FileSystemObject');
<! - Server-side with an OBJECT element ->
<OBJECT RUNAT = "SERVER" SCOPE = "PAGE" ID = "objFSO"
PROGID = "Scripting.FileSystemObject">
In the ASP page, the increase in a type library for the FileSystemObject is a very useful reference. This allows the definition of the use of its built-in constants directly, not as in the past instead of using the number of equivalent expressions. The whole script run-time library type library can be increased to any ASP page, the code is as follows:
<! - METADATA TYPE = "typelib" FILE = "C: \ WinNT \ System32 \ scrrun.dll" -> If you are in another directory to install Windows, you must edit the properties of the value of FILE.
Asp Base Articles
- Advanced Programming ASP 3.0 (17)
- Advanced Programming ASP 3.0 (18)
- Advanced Programming ASP 3.0 (19)
- Advanced Programming ASP 3.0 (20)
- Advanced Programming ASP 3.0 (21)
- Advanced Programming ASP 3.0 (22)
- Advanced Programming ASP 3.0 (23)
- Advanced Programming ASP 3.0 (24)
- Advanced Programming ASP 3.0 (25)
- Advanced Programming ASP 3.0 (26)
- Advanced Programming ASP 3.0 (27)
- Advanced Programming ASP 3.0 (28)
- Advanced Programming ASP 3.0 (29)
- ASP + new contacts (1)
- ASP + new contacts (2)
- ASP + new contacts (3)
- ASP + new contacts (4)
- On the implementation of the procedures the issue of speed, (continued asp, php and jsp dynamic programming languages, such as comparison)
- Has already been installed WIN2000 and IIS5 and PWS, how to debug on the local ASP
- Advanced Programming ASP 3.0 (a)
Can't Find What You're Looking For?
Rating: Not yet rated