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?
Transfers control to a Sub procedure, Function procedure, or dynamic-link library (DLL) procedure.
The CALL statement transfers control from one object program to another within the run unit. The program containing the CALL statement is the calling program; the program identified in the CALL statement is the called subprogram.
You call a Function procedure by using the procedure name, followed by the argument list in parentheses, in an expression. You can omit the parentheses only if you aren't supplying any arguments. However, your code is more readable if you always include the parentheses.
To call a Function procedure in an assignment statementUse the Function procedure name following the equal ( = ) sign in the assignment statement. Follow the procedure name with parentheses to enclose the argument list. If there are no arguments, you can optionally omit the parentheses.
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")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With