Windows Script Components  

<component> Element

Encloses an entire Windows Script Component definition.

<component id=componentid>
   script component information here


A string that uniquely identifies the script component. This value is useful if a document contains multiple script components or when you are generating one type library for several script components. Identifiers must begin with a letter and can contain no spaces. The identifier must be unique within a script component package.

If specified, this value functions as the class name for the script component in the host application. For example, if you specify the component ID "MyComponent" in the <component> element, the script component is identified as the class MyComponent in the Visual Basic object browser. If no component ID is specified, the default value is ComponentCoClass.


In script component files, an entire script component definition — including<registration>, <public> and <implements> elements — must appear inside a <component> element. If the file contains multiple script components, they must in turn be enclosed within a <package> element.


The following shows a simple but complete script component that includes a factorial method and a name property.

Note   A CDATA section is required to make the script in the <script> element opaque. For details, see Script Component Files and XML Conformance.
<?XML version="1.0"?>
   description="My Test Component"

   <property name="name"/>
   <method name="factorial"/>

<script language="VBScript">
   Function factorial(n)
      If isNumeric(n) Then
         If n <= 1 Then
            factorial = 1
            factorial = n*factorial(n-1)
         End If
         factorial = -2   ' Error code.
      End If
   End Function

See Also

Script Component File Contents