<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Variable Type detection?</title><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/1078cd574a/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/CODESYS-V2/thread/1078cd574a/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/CODESYS-V2/thread/1078cd574a/</id><updated>2020-02-27T21:08:28.040000Z</updated><subtitle>Recent posts to Variable Type detection?</subtitle><entry><title>Variable Type detection?</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/1078cd574a/?limit=25#4d4d" rel="alternate"/><published>2020-02-27T21:08:28.040000Z</published><updated>2020-02-27T21:08:28.040000Z</updated><author><name>shooter</name><uri>https://forge.codesys.com/u/shooter/</uri></author><id>https://forge.codesys.com889fcfbfa0c269deab0aea1212c534c33c18dd3a</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;i do it by paralleling inputs and outputs in ver 2 so input is real and int same as output.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Variable Type detection?</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/1078cd574a/?limit=25#444e" rel="alternate"/><published>2020-02-27T21:08:26.577000Z</published><updated>2020-02-27T21:08:26.577000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.come433a3f3585315b2bad8d1c5cda22319e1ed5db2</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;You could return the ANY type, but then you would have to determine which type within the ANY type.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Variable Type detection?</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/1078cd574a/?limit=25#8ce8" rel="alternate"/><published>2020-02-27T21:08:22.541000Z</published><updated>2020-02-27T21:08:22.541000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com25a461542ce217d830d1dd182b9b16ef3ed065c2</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; fk5&lt;/p&gt;
&lt;p&gt;&lt;span style="color: 120%;"&gt;So, it works this way for using different inputs. That's good.&lt;br/&gt;
But, I also want it to output into the same type as whatever is connected. &lt;br/&gt;
Is this possible?   (Example: I'd like to modify this function to work regardless if dd is a REAL, INT, BYTE, ...)&lt;/span&gt;&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;FUNCTION anyTestFunction : REAL&lt;br/&gt;
VAR_INPUT&lt;br/&gt;
    in1:        REAL := ANY_TO_REAL(in1);&lt;br/&gt;
    in2:        REAL := ANY_TO_REAL(in2);&lt;br/&gt;
    in3:        REAL := ANY_TO_REAL(in3);&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;anyTestFunction := in1 + in2 + in3;&lt;/p&gt;
&lt;hr/&gt;
&lt;hr/&gt;
&lt;p&gt;PROGRAM PLC_PRG&lt;br/&gt;
VAR&lt;br/&gt;
    aa:     INT     := 2;&lt;br/&gt;
    bb:     REAL    := 2.1;&lt;br/&gt;
    cc:     BYTE    := 3;&lt;br/&gt;
    dd:     REAL;&lt;br/&gt;
END_VAR&lt;/p&gt;
&lt;hr/&gt;
&lt;p&gt;dd := anyTestFunction(aa, bb, cc);&lt;br/&gt;
&lt;strong&gt;&lt;em&gt;*&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;*&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;*&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;*&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;*&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;*&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;*&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;*&lt;/em&gt;&lt;/strong&gt;&lt;strong&gt;&lt;em&gt;*&lt;/em&gt;&lt;/strong&gt;****&lt;/p&gt;
&lt;p&gt;&lt;img alt="IMG: any_num_01.png" rel="nofollow" src="https://forum.codesys.com//download/file.php?id=4992"/&gt;&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Variable Type detection?</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/1078cd574a/?limit=25#5dbb" rel="alternate"/><published>2020-02-27T21:08:21.098000Z</published><updated>2020-02-27T21:08:21.098000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com6e9cfed08f477944fc0aebcccbf9657555c6c020</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;Codesys V3 now supports the ANY_TYPE, which would work, but I don’t believe this is available on Codesys V2.3.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Variable Type detection?</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/1078cd574a/?limit=25#98c2" rel="alternate"/><published>2020-02-27T21:08:17.058000Z</published><updated>2020-02-27T21:08:17.058000Z</updated><author><name>WAGOKurt</name><uri>https://forge.codesys.com/u/wagokurt/</uri></author><id>https://forge.codesys.comf4708d2315acb6c6fcf5f4870022ea26b2311284</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;In this case I would use; INT_TO_REAL(your_var)  or WORD_TO_REAL(your_var) etc.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Variable Type detection?</title><link href="https://forge.codesys.com/forge/talk/Codesys%2520V2.3/thread/1078cd574a/?limit=25#5f6b" rel="alternate"/><published>2020-02-27T21:08:15.514000Z</published><updated>2020-02-27T21:08:15.514000Z</updated><author><name>Anonymous</name><uri>https://forge.codesys.com/u/*anonymous/</uri></author><id>https://forge.codesys.com77103984747b13a615f6342aa075082e82cc9ccf</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;&lt;em&gt;Originally created by:&lt;/em&gt; fk5&lt;/p&gt;
&lt;p&gt;Can CoDeSys do conditional variable type identification?&lt;/p&gt;
&lt;p&gt;Example:&lt;br/&gt;
I have a scale function that takes in a REAL value and scales it to some new range, then outputs a REAL. But, sometimes I’m trying to scale an INT, or a DINT, or a BYTE or  SINT, etc. how can I make this function automatically recognize the input type, do a xxx_TO_REAL, run my scale function, then do a REAL_TO_xxx, then output the result as an xxx instead of a REAL? &lt;/p&gt;
&lt;p&gt;Any solution besides “make a different function for each variable type” would be awesome. &lt;/p&gt;
&lt;p&gt;Thanks!&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>