<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to function arguments and types/cast</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/aa50c2eabf/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/aa50c2eabf/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/aa50c2eabf/</id><updated>2020-02-27T13:59:30.178000Z</updated><subtitle>Recent posts to function arguments and types/cast</subtitle><entry><title>function arguments and types/cast</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/aa50c2eabf/?limit=25#96cb" rel="alternate"/><published>2020-02-27T13:59:30.178000Z</published><updated>2020-02-27T13:59:30.178000Z</updated><author><name>timvh</name><uri>https://forge.codesys.com/u/timvh/</uri></author><id>https://forge.codesys.com2a771cbd201bbdc1dde2176ce86182ceb3ae9dab</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;You can also use:&lt;br/&gt;
REAL#2&lt;br/&gt;
instead of&lt;br/&gt;
TO_REAL(2)&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>function arguments and types/cast</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/aa50c2eabf/?limit=25#8bc0" rel="alternate"/><published>2020-02-27T13:59:29.937000Z</published><updated>2020-02-27T13:59:29.937000Z</updated><author><name>ranthony63</name><uri>https://forge.codesys.com/u/ranthony63/</uri></author><id>https://forge.codesys.com6a0892fd210282fd16599c4cf9c89c8f40a58fa0</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Thanks Comingback4u. Using VAR_IN_OUT + constant value input was indeed the problem.&lt;/p&gt;
&lt;p&gt;Thanks scott_cunningham for the tip with &lt;br/&gt;
(TO_INT)2, r1:=(TO_REAL)11.1, r2:=(TO_REAL)20&lt;br/&gt;
I didn't know it and it might be useful in the future.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>function arguments and types/cast</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/aa50c2eabf/?limit=25#5a54" rel="alternate"/><published>2020-02-27T13:59:29.200000Z</published><updated>2020-02-27T13:59:29.200000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com21e30690c472b5147f1122c52397f324872f33b8</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; scott_cunningham&lt;/p&gt;
&lt;p&gt;Good catch, Comingback4u, using VAR_IN_OUT is not helping and is probably why the poster saw this problem!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>function arguments and types/cast</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/aa50c2eabf/?limit=25#9698" rel="alternate"/><published>2020-02-27T13:59:28.963000Z</published><updated>2020-02-27T13:59:28.963000Z</updated><author><name>Comingback4u</name><uri>https://forge.codesys.com/u/comingback4u/</uri></author><id>https://forge.codesys.com336495ba1ff2d86062422fedd5ac50fcfd803b02</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Isn't using VAR_IN_OUT referencing the memory location of the variable being passed in? If you pass direct values in there is no memory location to reference. VAR_INPUT should be used if you don't want to use variables.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>function arguments and types/cast</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/aa50c2eabf/?limit=25#4a63" rel="alternate"/><published>2020-02-27T13:59:28.707000Z</published><updated>2020-02-27T13:59:28.707000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com83c476a6719a0aeb2a84bed2faa394623d350ab7</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; scott_cunningham&lt;/p&gt;
&lt;p&gt;Have you tried: &lt;/p&gt;
&lt;p&gt;MyFunc(I:=(TO_INT)2, r1:=(TO_REAL)11.1, r2:=(TO_REAL)20);&lt;/p&gt;
&lt;p&gt;Also, in the project settings there may be a setting to treat LREAL as a REAL.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>function arguments and types/cast</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/aa50c2eabf/?limit=25#e986" rel="alternate"/><published>2020-02-27T13:59:28.464000Z</published><updated>2020-02-27T13:59:28.464000Z</updated><author><name>ranthony63</name><uri>https://forge.codesys.com/u/ranthony63/</uri></author><id>https://forge.codesys.com691a1071ad6d179036199bd270268c0042cf12b1</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have a problem with types when passing arguments involving direct numerical value.&lt;/p&gt;
&lt;p&gt;The function definition:&lt;br/&gt;
FUNCTION myFunc: BOOL&lt;br/&gt;
VAR_IN_OUT&lt;br/&gt;
    i : INT;&lt;br/&gt;
    r1: REAL;&lt;br/&gt;
        r2: REAL;&lt;br/&gt;
...&lt;/p&gt;
&lt;p&gt;If in PLC_PRG I call the function like this:&lt;br/&gt;
myFunc(i:=2, r1:=11.1, r2:=800);&lt;/p&gt;
&lt;p&gt;It gives me a compile error because 2 is seen as a SINT and not an INT, 11.1 is seen as LREAL, while 800 is seen as REAL (OK for compiler).&lt;/p&gt;
&lt;p&gt;But if I declare variables in PLC_PRG and then call the function myFunc it works. Like this:&lt;/p&gt;
&lt;p&gt;VAR&lt;br/&gt;
i : INT;&lt;br/&gt;
r1: REAL;&lt;br/&gt;
r2: REAL;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;p&gt;i:=2;&lt;br/&gt;
r1:=11.1;&lt;br/&gt;
r2:=800;&lt;br/&gt;
myFunc(i,r1,r2);&lt;/p&gt;
&lt;p&gt;I would really like to have the one-liner written above working for compactness in big programs. Can you please help me figure out how to do that? The idea is to be able to set many parameters to constants with one line.&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>