Im trying to use a function in a program. Always getting some syntax error. Just trying to send 2 variables to a function and add them , then sending the result back . The function only needs to be accessible from the main program. Probably some error with declarations or something, but I don't get it.
Code:
Func3();
EXPORT Test()
BEGIN
LOCAL a;
a := Func3(3,4);
END;
Func3(a,b);
LOCAL a,b,c;
c := a + b;
RESULT(c);
END;
Remove the ; from the func declaration, and add BEGIN
I think you need a BEGIN and END in the function and I dont think you need the a,b variables in Local and I believe result should be RETURN (c)
I will show 3 versions. All of them will behave identically.
Code:
Func3(a,b)
begin
local c;
c := a + b;
return c;
end;
Code:
Func3(a,b)
begin
local c;
c := a + b;
end;
Code:
Func3(a,b)
begin
a + b;
end;
Note that the reason these all behave the same is that there is *always* an implicit return on the last item in the runstream of the program. A function must return a single result. That result might not be used for anything, but it must return at least one thing.
Ok Func3(a,b); was wrong (no semicolon) and I needed a BEGIN. RESULT is pascal syntax should be: return. Seems as return c; and return(c); both works.
Thank you for the replies.
When creating a function with input variables, those variables are implicitly declared as local. Therefore, you would not use a LOCAL statement with them. For example,
Code:
EXPORT MYFUNC(a,b)
BEGIN
RETURN(a+b);
END;
The variables
a and
b do not need a
LOCAL a,b statement inside the BEGIN END pair.