# Function calling

**URL:** https://tech-community.robotics.abb.com/t/function-calling/5261
**Category:** RobotStudio
**Created:** [December 6, 2012, 9:23pm UTC](https://tech-community.robotics.abb.com/t/function-calling/5261 "2012-12-06T21:23:52Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![phateee](https://avatars.discourse-cdn.com/v4/letter/p/3bc359/32.png) [@phateee](https://tech-community.robotics.abb.com/u/phateee)
#### Post date: [December 6, 2012, 9:23pm UTC](https://tech-community.robotics.abb.com/t/function-calling/5261/1 "2012-12-06T21:23:52Z")

</div>

Hello, I am a beginner in programming.I try to make procedure with parametr VAR or INOUT and compiler write me error. I think, that calling procedure with VAR or INOUT is something as pointer in language C/C++. For example:

MODULE A PROC routine(VAR num u)

…

ENDPROC

PROC main()

VAR num x;

routine(x);

ENDPROC

ENDMODULE

And compiler write:

Argument error(124): Argument for ‘VAR’ parameter x is not variable reference or is read only  
Thank you for your advice

---

<div class="post-metadata">

### Author: ![Henrik\_Berlin](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/henrik_berlin/32/1011_2.png) [@Henrik\_Berlin](https://tech-community.robotics.abb.com/u/Henrik_Berlin)
#### Post date: [December 6, 2012, 10:45pm UTC](https://tech-community.robotics.abb.com/t/function-calling/5261/2 "2012-12-06T22:45:54Z")

</div>

Try this instead:

[CODE]MODULE A

PROC routine(INOUT num u)  
u:=2\*u;  
ENDPROC

PROC main()  
VAR num x:=1;  
TPWrite "Before routine: x = "Num:=x;  
routine x;  
TPWrite "After routine: x = "Num:=x;  
ENDPROC

ENDMODULE[/CODE]

You can see the result in the Operator panel below:

---

<div class="post-metadata">

### Author: ![Henrik\_Berlin](https://dub1.discourse-cdn.com/flex005/user_avatar/tech-community.robotics.abb.com/henrik_berlin/32/1011_2.png) [@Henrik\_Berlin](https://tech-community.robotics.abb.com/u/Henrik_Berlin)
#### Post date: [December 6, 2012, 10:47pm UTC](https://tech-community.robotics.abb.com/t/function-calling/5261/3 "2012-12-06T22:47:26Z")

</div>

The RAPID Overview manual contains a description of INOUT, see  
[http://www.scribd.com/doc/71173119/Rapid-Overview-Manual#page=112](http://www.scribd.com/doc/71173119/Rapid-Overview-Manual#page=112)

---

<div class="post-metadata">

### Author: ![Thomas\_J](https://avatars.discourse-cdn.com/v4/letter/t/f475e1/32.png) [@Thomas\_J](https://tech-community.robotics.abb.com/u/Thomas_J)
#### Post date: [December 7, 2012, 5:33pm UTC](https://tech-community.robotics.abb.com/t/function-calling/5261/4 "2012-12-07T17:33:03Z")

</div>

The reason you received the above message is because “routine(x)” implies a functin with a return value - the correct use of your format is

x:=routine(x); where routine is defined as a funtion with a return value.

FUNC num routine(num u)  
RETURN 2\*u;  
ENDFUNC

The instruction call syntax when passing variables or parameters is “routine x;” without ()  
functin call syntax is “num:=routine(num);”. with ()

Whenever you use the parentheses () RAPID interprets it as passing parameters to a function that will return a value.

To understand the difference please read the Introduction to RAPID section

| “RAPID instructions and functions” |
| --- |

A RAPID function is similar to an instruction but returns a value  
Since the function returns a value, the result of the function can be assigned to a variable. The arguments in a function call are written inside parenthesis and are separated with commas.

An instruction call looks like a procedure call with the instruction name followed by argument values not enclosed in parnthesis.

Hope this helps…
