Post Reply 
Using function in program
01-26-2014, 06:56 PM
Post: #1
Using function in program
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;
Find all posts by this user
Quote this message in a reply
01-26-2014, 07:25 PM
Post: #2
RE: Using function in program
Remove the ; from the func declaration, and add BEGIN

My website: erwin.ried.cl
Visit this user's website Find all posts by this user
Quote this message in a reply
01-26-2014, 07:27 PM
Post: #3
RE: Using function in program
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)
Find all posts by this user
Quote this message in a reply
01-26-2014, 07:36 PM
Post: #4
RE: Using function in program
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.

TW

Although I work for HP, the views and opinions I post here are my own.
Find all posts by this user
Quote this message in a reply
01-26-2014, 09:27 PM (This post was last modified: 01-26-2014 09:28 PM by Graan.)
Post: #5
RE: Using function in program
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.
Find all posts by this user
Quote this message in a reply
01-26-2014, 09:28 PM
Post: #6
RE: Using function in program
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.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 1 Guest(s)