Call Statement

   
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 defined using the Declare statement, you can override the default method of passing an argument by specifying the ByVal or ByRef keywords before the argument. In VB.NET you cannot change whether an argument is passed by value or by reference in the call to the routine.

See Also

CallByName Function

   


VB.Net Language in a Nutshell
VB.NET Language in a Nutshell
ISBN: B00006L54Q
EAN: N/A
Year: 2002
Pages: 503

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net