Call Keyword

At some point you will need to split your code into more than one subroutine or procedure.
When you have more than one subroutine, you can pass execution to a different subroutine by placing the name of the subroutine on a new line.

Sub Procedure_One() 
   Procedure_Two
End Sub

You can prefix the name of the subroutine with the Call keyword, this is valid syntax.

Sub Procedure_One() 
   Call Procedure_Two
End Sub

Using the Call keyword is considered redundant now, which is a shame. because it does make your code more readable.
This syntax actually comes from the days of BASIC when every line had to start with a keyword.


With Parameters

When you are passing arguments into a subroutine, you need to pass them as a comma delimited list.

Sub Procedure_One() 
   Procedure_Two Arg1, Arg2, Arg3
End Sub

The Call keyword can also be used here.
Passing in parameters when using the Call keyword, does require the parameters to be enclosed in parentheses.

Sub Procedure_One() 
   Call Procedure_Two(Arg1, Arg2, Arg3)
End Sub

Despite the Call keyword being redundant, some people consider the parentheses to help with readability.


Parentheses without the Call

If you use the built-in MsgBox to display a dialog box the syntax should be one of the following:

MsgBox "hello world" 
Call MsgBox("hello world")

The following syntax is valid, and has the same result, but is very bad practice.
Although the end result is the same, these arguments are actually getting evaluated first.

MsgBox ("hello world") 

For more information on this, refer to the Evaluated First page.


When Call Is Required

The Call statement can be used to call a dynamic link library procedure.
There are in fact a very small number of situations where using the Call keyword is required.


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext