PDA

View Full Version : How Does the Call Command Work?



SimonB
08-11-2008, 07:32 AM
How does the Call command work, as in "Call SubProcedure", with respect to program flow and branching? From my old Fortran days, I would expect it to pass program control to the procedure being called, and when that procedure is finished, control by default passes back to the calling procedure at the place where the initial Call was loacted. Is this the case? It doesn't seem to be. Rather the Call command seems to direct the flow to the new procedure and it never returns to the calling procedure.

If it does by default return control to the calling procedure, then how do you terminate or redirect program flow so that it does NOT return to the calling procedure in a case where that is desired? Is there a command that voids the automatic return to the calling procedure?

This is different from the issue of passing parameters back and forth between procedures. That I understand.

Any help on how this program flow/branching works would be appreciated.

SimonB

CreganTur
08-11-2008, 07:58 AM
You don't have to use the Call keyword when calling another procedure- but if you do you have to put your arguments in parantheses. If you don't use the Call keyword, then don't use the parentheses.

Calling a procedure should work as you described- it passes control from the Calling procedure to the Called procedure, and then control is passed back to the Calling procedure at the end.


Is this the case? It doesn't seem to be.
Could an error be occuring in your Called procedure that you're not aware of? This could possibly terminate code execution, which would prevent control from moving back to the Calling procedure.

If you want to share your code (please wrap in VBA tags) we can take a look at it, if you think it would help.