Windows Script Components  

<reference> Element

Includes a reference to an external type library.

<reference [object="progID" |guid="typelibGUID"] [version="version"]>

Values

progID
The program ID from which the type library can be derived, which can include a version number (for example, ADO.Recordset.2.0). This can include the explicit program ID of a type library, or the program ID of the executable (such as a .DLL) that incorporates the type library. If you use the object attribute, you do not need to specify a version attribute, because the version can be inferred from the program ID.

If the object attribute is specified, you cannot also specify a guid attribute.

typelibGUID
The GUID of the type library to reference. If the guid attribute is specified, you cannot also specify an object attribute.
version
(Optional) The version number of the type library to use. It must be in the form <major version>[.<minor version>]. If a version is not specified, the default version is 1.0. If the object attribute is used to specify the type library and the version is not specified, the version is derived from the Registry key for the specified program ID. If none can be found, the default is 1.0.

Remarks

Referencing a type library in your script component allows you to use constants defined in the type library in scripts. The <reference> element looks up and makes available the type library associated with a specific program ID or type library name. Type library information can be available in .tlb, .olb, or .dll files.

The <reference> element should appear inside the <component> element. If there is more than one script component in the package, the type library applies to only the script component in whose <component> element it is declared.

Example

In the following script component fragment, referencing the type library for ADO (contained in the file MSAD015.DLL) allows you to use ADO constants such as adStateOpen in your scripts.

Note   A CDATA section is required to make the script in the <script> element opaque. For details, see Script Component Files and XML Conformance.
<reference object="ADODB.Connection.2.0"/>
<registration progid="ADOScriptlet"/>
<public>
   <property name="cnnstate"/>
   <method name="openConnection"/>
   <method name="closeConnection"/>
</public>

<script language="VBScript">
<![CDATA[
Dim cnn
Dim cnnState
Function openConnection()
   Set cnn = CreateObject("ADODB.Connection")
   cnn.ConnectionString = 
      "driver={SQL Server};server=myserver;uid=sa;database=pubs"
   cnn.Open
   If cnn.State = adStateOpen Then
      cnnState = "open"
   Else
      cnnState = "closed"
   End If
End Function

Function closeConnection()
   cnn.Close
   cnnState = "closed"
End Function
]]>
</script>

See Also

Referencing Other Components