Windows Script Components  

<method> Element

Declares a method.

<method name="methodName" internalName="functionName" dispid=dispID>
   [<parameter name="parameterID"/>]


The name of the method to expose.
(Optional) The name of the procedure (function or subroutine) in the script component file that implements the method. If you do not specify an internal name, methodName is used.
Tip   In XML, you can implement elements that have no content (such as the <method> element) by closing the element with />.
(Optional) COM dispatch ID for the method. If no dispid is specified, the dispid is automatically generated. If the dispid is set to 0 (zero), the method becomes the script component's default method. For more information about dispids, see Exposing Events.
If a parameter is explicitly declared for the method, identifies the parameter's name.


A method is implemented as a procedure (function or subroutine) in a separate <script> element. The <method> element maps the name of the method to the procedure used to implement it.

You can optionally declare the parameters for your method. Doing so is not required, but exposes parameter information if you generate a type library for your script component (see Creating a Script Component Type Library).


The following script component fragment defines two methods (factorial and random). The random method includes definitions for its parameters, and binds to a function called getRandomNumber.

Note   A CDATA section is required to make the script in the <script> element opaque. For details, see Script Component Files and XML Conformance.
   <method name="factorial"/>
   <method name="random" internalName="getRandomNumber">
      <parameter name="upperBound">
      <parameter name="seed">

<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

   Function getRandomNumber(upperBound, seed)
      upperBound = CInt(upperBound)
      getRandomNumber = Cint(upperBound * Rnd(seed) + 1)
   End Function

See Also

<event> Element | <property> Element | Exposing Events | Exposing Methods | Exposing Properties