<< Prev        Next >>

ID : 472

Calling a Procedure with Argument

Other procedures in the task can be called by using a Call statement and a Run statement from the procedure.

In the procedure declaration, it is specified whether or not to request the argument to the caller.

Sub aaa(ByRef bbb As Integer)

In the example above, it is expressed that the aaa procedure is accompanied by an integer type argument bbb.

Make up the number of arguments. Arguments cannot be omitted.

There are 2 ways to pass arguments to a procedure:

Pass by reference
To be designated by ByRef. When a variable value passed by the procedure on the call target side is changed, the variable on the caller side is also changed.
Pass by value
To be designated by ByVal. Even when a variable value passed by the procedure on the call target side is changed, the variable on the caller side is not changed.

A Call statement can designate both pass by reference and pass by value, while a Run statement can only designate pass by value. An error occurs when the procedure called by a Run statement designates pass by reference.

Example of Pass by Reference

Sub aaa
	dim bbb As Integer
	bbb = 10
	Call ccc(bbb)
	PrintDbg bbb 'bbb is 11.
End Sub

Sub ccc(ByRef ddd As Integer)
	ddd = ddd + 1
End Sub

Example of Pass by Value

Sub aaa
	Dim bbb As Integer
	bbb = 10
	Call ccc(bbb)
	PrintDbg bbb 'bbb is 10.
End Sub

Sub ccc(ByVal ddd As Integer)
	ddd = ddd + 1
End Sub

Attention

The case that an argument can NOT be passed

It will be a error in the case that an argument required by procedure can not be passed.

Do not allow a procedure on call to resquest an argument since it can not be called with argument in the following cases.

  • Start from I/O
  • Start-up setting at power start up for object file in a supervisory task
  • Start-up setting at automatic mode switching for object file in a supervisory task

ID : 472

<< Prev        Next >>