Page

10.2.1- Creating an Instance of a Scripting Runtime Object

Created by Brendan Doss.
Last Updated by Brendan Doss.  

PublicCategorized as 10. The Scripting Objects.

Not yet tagged
<< 10.2.0- Creating an Instance of a Scripting ObjectChapter1010.2.2- Creating an instance of a VBScript object >>

Creating an Instance of a Scripting Runtime Object

In ASP, we create an instanceof an object in the Set statement with the CreateObject method and the location and name of the object. The locationand name of the object goes together to create a unique identifier for theobject known as a ProgID. So theProgID for the Dictionary object is Scripting.Dictionary. Used in conjunction with the CreateObject method itwould look like this:

 

CreateObject("Scripting.Dictionary")

 

Once we've created aninstance, it must be assigned to a variable name (the above line wouldn't workon its own) – this allows you to refer to the instance later on in your code.

 

Although you can use anyname, many programmers prefix the name of their object (and indeed oursuggested naming convention does), by appending the letters obj before it. Forexample, if you were using an instance of the Dictionary object, then you might want to give it a variablename like objDictionary or objDict. A typicalinstantiation might look something like this:

 

Set objDictionary = CreateObject("Scripting.Dictionary")

 

Instantiation is the namewe give to the process of creating an instance of an object. For example, inthis piece of code we have instantiated objDictionary, which is an instance of the Dictionary object.

As you can see, we have usedthe Setstatement, followed by the name that we have chosen for our instance. Onceyou've used the Set statement, and the CreateObject method in this way, the instance of theobject will be ready to use. Subsequently, you use the instance by referring toit using the name you give within the Set statement.

<< 10.2.0- Creating an Instance of a Scripting ObjectChapter1010.2.2- Creating an instance of a VBScript object >>

Copyright © 2003 by Wiley Publishing, Inc.

Powered by Near-TimeTerms of Services | Privacy Policy | Security Policy |