What does the Call keyword do in VB6? What does the Call keyword do in VB6? vba vba

What does the Call keyword do in VB6?


From the MSDN:

You are not required to use the Call keyword when calling a 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, you also must omit the parentheses around argumentlist. If you use either Call syntax to call any intrinsic or user-defined function, the function's return value is discarded.

For example:

Sub Proc1()    Debug.Print "Hello World"End SubSub Proc2(text As String)    Debug.Print "Hello " & textEnd Sub

In the immediate window, if you enter

Proc1

then "Hello World" prints. If you enter

Call Proc1

then "Hello World" prints. If you enter

Proc2 "World"

then "Hello World" prints. If you enter

Call Proc2 "World" 

you get a compile error. You would have to enter

Call Proc2("World")


Call does nothing special other than call the method. It is a hang over from the old days of Basic when all lines had to start with a keyword. "Let" is another of these keywords, which was always put before an assignment, but is no longer required.

Method1 and Method2 do the exact same thing.


I have found a major difference about 'call' keyword with functions that having, ByRef Arguments (I have found this in MS-Access VBA editor). If you are calling the function without 'Call' keyword, ByRef aruments will not set for the calle. For Ex:

Private Function Test(Optional ByRef refArg As String) As Boolean        refArg = "Test"    Test = TrueEnd Function

If you call the function without the Call keyword like

Dim a As StringTest(a)

a will be an empty string, after the call returns

If you call the function with the Call keyword like

Dim a As StringCall Test(a)

a will contain the string Test

The detailed explanation provided in the following link:http://blogs.msdn.com/b/ericlippert/archive/2003/09/15/52996.aspx