<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to how to define a function</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/8e84450d16/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/8e84450d16/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/8e84450d16/</id><updated>2020-02-27T19:59:38.616000Z</updated><subtitle>Recent posts to how to define a function</subtitle><entry><title>how to define a function</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/8e84450d16/?limit=25#0e10" rel="alternate"/><published>2020-02-27T19:59:38.616000Z</published><updated>2020-02-27T19:59:38.616000Z</updated><author><name>shooter</name><uri>https://forge.codesys.com/u/shooter/</uri></author><id>https://forge.codesys.com01c5060dd617a75d49fa30db7596b627afb5a192</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;FUNCTION myFunction : INT&lt;br/&gt;
VAR_INPUT&lt;br/&gt;
a:INT;&lt;br/&gt;
b:INT;&lt;br/&gt;
c:INT;&lt;br/&gt;
END_VAR&lt;br/&gt;
VAR&lt;/p&gt;
&lt;p&gt;END_VAR&lt;/p&gt;
&lt;p&gt;in the function body&lt;br/&gt;
I wrote&lt;br/&gt;
myfunction :=a+b+c;  &amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&amp;lt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>how to define a function</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/8e84450d16/?limit=25#eee8" rel="alternate"/><published>2020-02-27T19:59:37.318000Z</published><updated>2020-02-27T19:59:37.318000Z</updated><author><name>liuyongzhi</name><uri>https://forge.codesys.com/u/liuyongzhi/</uri></author><id>https://forge.codesys.com6b72ab8d6600815cc06d166e0bbdb1a1fd939546</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I suggest in PRG:&lt;/p&gt;
&lt;p&gt;VAR&lt;br/&gt;
mycallOutput : INT;&lt;br/&gt;
onefunction: myFunction; //POU type of myFunction&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;in code body:&lt;/p&gt;
&lt;p&gt;mycallOutput : = onefunction(x, y, z);&lt;/p&gt;
&lt;p&gt;The way you are doing is using a POU type for processing, in fact no function instance is created, so there is output is default 0. Hope Codesys can explain the compiling process. I think the program should not pass compilation.&lt;/p&gt;
&lt;p&gt;Yongzhi&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>how to define a function</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/8e84450d16/?limit=25#2685" rel="alternate"/><published>2020-02-27T19:59:36.015000Z</published><updated>2020-02-27T19:59:36.015000Z</updated><author><name>shooter</name><uri>https://forge.codesys.com/u/shooter/</uri></author><id>https://forge.codesys.com6ee898e24c87647f87428dd7ffa49440e80f9350</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;as the function has no idea what the output is you will have to define it.&lt;br/&gt;
so your x should be myfunction&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>how to define a function</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/8e84450d16/?limit=25#ca45" rel="alternate"/><published>2020-02-27T19:59:32.378000Z</published><updated>2020-02-27T19:59:32.378000Z</updated><author><name>keobe</name><uri>https://forge.codesys.com/u/keobe/</uri></author><id>https://forge.codesys.com7a371fefd0d8e0cd9ed0aeecad444670318db625</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi&lt;br/&gt;
I like to define a function named myFunction with input parameters a,b,and c&lt;/p&gt;
&lt;p&gt;I wrote the function like this&lt;/p&gt;
&lt;p&gt;FUNCTION myFunction : INT&lt;br/&gt;
VAR_INPUT&lt;br/&gt;
    a:INT;&lt;br/&gt;
    b:INT;&lt;br/&gt;
    c:INT;&lt;br/&gt;
END_VAR&lt;br/&gt;
VAR&lt;br/&gt;
    x:INT;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;in the function body&lt;br/&gt;
I wrote&lt;br/&gt;
x:=a+b+c;&lt;/p&gt;
&lt;p&gt;when i call the function, I got the output =0, can someone pls help me why I got the answer =0?&lt;/p&gt;
&lt;p&gt;my prg is&lt;/p&gt;
&lt;p&gt;PROGRAM PLC_PRG&lt;br/&gt;
VAR&lt;br/&gt;
    mycallOutput:INT;&lt;br/&gt;
    x:INT;&lt;br/&gt;
    y:INT;&lt;br/&gt;
    z:INT;&lt;/p&gt;
&lt;p&gt;END_VAR&lt;/p&gt;
&lt;p&gt;prog:&lt;/p&gt;
&lt;p&gt;x:=4;&lt;br/&gt;
y:=5;&lt;br/&gt;
z:=6;&lt;br/&gt;
mycallOutput:=myFunction(x,y,z);&lt;/p&gt;
&lt;p&gt;result is mycallOutput =0;&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>