O'Reilly logo

VBScript in a Nutshell, 2nd Edition by Ron Petrusha, Matt Childs, Paul Lomax

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Name

Call Statement

Syntax

[Call] procedurename [argumentlist]
Call

Use: Optional

Use: Required

Data Type: n/a

The name of the subroutine being called.

argumentlist

Use: Optional

Data Type: Any

A comma-delimited list of arguments to pass to the subroutine being called.

Description

Passes program control to an explicitly named procedure or function.

Rules at a Glance

  • The Call statement requires that the procedure being called be named explicitly. You cannot assign the subroutine name to a variable and provide that as an argument to the Call statement. For example, the following is an illegal use of Call:

    Dim sProc
    sProc = "PrintRoutine"
    Call sProc(sReport)       ' Illegal: sProc is a variable

    The following code fragment shows a valid use of the Call statement:

    Call PrintRoutine(sReport)         ' Legal usage
  • You aren’t required to use the Call keyword when calling a function procedure. However, if you use the Call keyword to call a procedure that requires arguments, argumentlist must be enclosed in parentheses. If you omit the Call keyword from the procedure call, you must also omit the parentheses around argumentlist.

Example

The WSH code fragment shows a call to a procedure that passes two arguments: a string array and a string. Note that while the call to the ShowList procedure uses the Call keyword, the equivalent call to the MsgBox function within the ShowList procedure does not:

Dim aList, sCaption aList = Array("One", "Two", "Three", "Four") sCaption = "Array Contents" Call ShowList(aList, sCaption) Sub ShowList(arr( ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required