Name

Call Statement

Syntax

[Call]procedurename[(argumentlist)]
procedurename

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 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 ...

Get VB .NET Language in a Nutshell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.