Windows Script Components  

Referencing Other Components

Your Windows® Script Component can include references to external components that you need to create the script component, such as:

Referencing Additional COM Components

In your script component, it might be necessary to create instances of other COM components as needed. You can do so in two ways:

To create an OBJECT element

The following example shows an object definition in a script component.

<object id="cnn" progid="ADODB.Connection"/>

Referencing an External Type Library

Many components that you might work with support type libraries, which provide a complete listing of the component's classes and their members. By referencing the component's type libraries, you can use constants defined in the type library.

To include a reference to a type library

Referencing Resources

Resource elements can include information that might change between versions, strings that might be translated, and other values.

To reference resources

  1. In the script component, but outside of the <public> and <script> elements (and <implements> element, if any), create one <resource> element for each resource you want to define, giving each element a unique ID. The following example shows two <resource> elements:
    Note   A CDATA section is required to make the contents of the <resource> element opaque to the parser. For details, see Script Component Files and XML Conformance.
    <component id="MyScriptlet">
    <public>
       <method name="random" internalName="getRandomNumber"/>
    </public>
    <resource id="errNonNumeric"><![CDATA[Non-numeric value passed]]>
    </resource>
    <resource id="errOutOfRange"><![CDATA[Passed value is out of range ]]>
    </resource> 
  2. In your script, include the resource text or number by calling the getResourcefunction, as shown in the following example.
    Note   A CDATA section is required to make the script in the <script> element opaque to the parser. For details, see Script Component Files and XML Conformance.
    <script language="VBScript">
    <![CDATA[
    Function getRandomNumber(upperBound)
       If IsNumeric(upperBound) Then
          getRandomNumber = Cint(upperBound * Rnd + 1)
       Else
          getRandomNumber=getResource("errNonNumeric")
       End If
    End Function
    ]]>
    </script>

See Also

Script Component File Contents | Referencing Another Script Component in the Same Package