Call Keyword

Any parameters must be enclosed in parenthese when using the Call keyword.
The Call statement can be used to call a procedure, function or dynamic link library procedure.

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

When calling a procedure you can omit the Call keyword.
If you do you must also omit the parenthese around your arguments.
Doing this makes you code harder to read because you can not quickly identify the procedure and function calls.

Public Sub Procedure_Name 
   DisplayTwoNumbers 20, 30
End Sub

Using the Call keyword though is encouraged as it makes it very clear that another procedure is being called.


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

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

Public procedures can be called from anywhere
Private procedures can only be called from within the current module


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

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

When you call a public procedure that lies in another module there is a potential for ambiguity as there may be a procedure with the same name in another module
You should always fully qualify your procedure names with the name of the module.

Call ModuleName.ProcedureName() 

If necessary specify the project name as well

Call ProjectName.ModuleName.ProcedureName() 


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