Search code examples
vbavb6syntax

What does the Call keyword do in VB6?


There's some code in our project that looks a bit like this:

Private Sub Method1()
    Call InnerMethod
End Sub

Private Sub Method2()
    InnerMethod
End Sub

Private Sub InnerMethod()
    '' stuff
End Sub

What's the advantage of doing Method1 over Method2?


Solution

  • 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 Sub
    
    Sub Proc2(text As String)
        Debug.Print "Hello " & text
    End 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")