Call Keyword

When calling a subroutine you can omit the Call keyword.
If you do, you must also omit the parentheses around your arguments.
Doing this makes you code harder to read because at quick glance it is not obvious if this is a subroutine or a function call.

Public Sub Procedure_Name 
   DisplayTwoNumbers 20, 30
End Sub

Using the Call keyword is good practice because it makes it very clear when another procedure is being called.
Any parameters must be enclosed in parentheses when using the Call keyword.

Public Sub Procedure_Name 
   Call DisplayTwoNumbers(20, 30)
End Sub

The Call statement can be used to call a procedure, function or dynamic link library procedure.

Public Sub DisplayTwoNumbers(ByVal iNumber1 As Integer, _ 
                             ByVal iNumber2 As Integer)
Dim itotal As Integer

   itotal = iNumber1 + iNumber2
   Call Msgbox(itotal)
End Function

There are infact a very small number of situations where using the Call keyword is required.


No Parameters

If your subroutine does not require any parameters you still need to include the parentheses.
You will soon release that including the Call keyword makes your code a lot easier to read.

Public Sub Procedure1() 
   Call MsgBox("You have entered procedure 1")
   Call Procedure2()
   Call MsgBox("You have returned to procedure 1")
End Sub

Public Sub Procedure2()
   Call MsgBox("You have entered procedure 2")
End Sub

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