O'Reilly logo

VB.NET Language in a Nutshell, Second Edition by Steven Roman PhD, Paul Lomax, Ron Petrusha

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)]
procedurename (required; n/a)

The name of the subroutine being called

argumentlist (optional; any)

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

Description

Passes execution control to a procedure, function, or dynamic-link library (DLL) procedure or function

Rules at a Glance

  • Use of the Call keyword is optional.

  • Regardless of whether the Call keyword is used, argumentlist, if it is present, must be enclosed in parentheses.

  • If you use Call to call a function, the function’s return value is discarded.

Example

Call myProcedure(True, iMyInt)

Sub myProcedure(blnFlag as Boolean, iNumber as Integer)
...
End Sub

Programming Tips and Gotchas

  • To pass a whole array to a procedure, use the array name followed by empty parentheses.

  • Some programmers suggest that code is more readable when the Call keyword is used to call subroutines.

VB.NET/VB 6 Differences

  • In VB 6, parentheses had to be omitted if the Call keyword was omitted and procedurename had more than one argument. In VB.NET, parentheses are required whenever arguments are present.

  • In VB 6, if argumentlist consisted of a single argument, enclosing it in parentheses and omitting the Call statement reversed the method by which the argument was passed to the called function. Thus, an argument ordinarily called by value would be called by reference, and vice versa. In VB.NET, this confusing behavior is not supported.

  • In VB 6, when calling an external routine ...

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