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
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:
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…