Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

ASP CreateObject Method

ASP CreateObject Method


Server Object Reference Complete Server Object Reference Manual


The CreateObject method creates an instance of an object.

**Note:** Objects created with this method have page scope. This means that after the current ASP page has finished processing, the server automatically destroys these objects. To create objects with session or application scope, you can use the tag in the Global.asa file and set the SCOPE attribute to session or application, or store the object in a session or application variable.

Syntax

Server.CreateObject(progID)

Parameters Description
progID Required. The type of object to create.

Example 1

This example creates an instance of the server component MSWC.AdRotator:

<%

Set adrot=Server.CreateObject("MSWC.AdRotator")

%>

Example 2

When the session ends, the object stored in a session variable is destroyed. However, you can also destroy the object by setting the variable to Nothing or to a new value:

<%

Session("ad")=Nothing

%>

or:

<%

Session("ad")="a new value"

%>

Example 3

You cannot create an object instance with the same name as a built-in object. For example, the following script will return an error:

<%

Set Application=Server.CreateObject("Application")

%>


Server Object Reference Complete Server Object Reference Manual