<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Variable name to string</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/15f032303a/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/15f032303a/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/15f032303a/</id><updated>2020-02-27T14:11:48.968000Z</updated><subtitle>Recent posts to Variable name to string</subtitle><entry><title>Variable name to string</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/15f032303a/?limit=25#262c" rel="alternate"/><published>2020-02-27T14:11:48.968000Z</published><updated>2020-02-27T14:11:48.968000Z</updated><author><name>jzhvymetal</name><uri>https://forge.codesys.com/u/jzhvymetal/</uri></author><id>https://forge.codesys.com33e05365841a8ae9f40fbfae32d87b97e869b0d0</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;singleton hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Hi Strucc,&lt;br/&gt;
he was asking for variable instances not for FB instances. That's why I did not offer this instance-path stuff &lt;br/&gt;
But anyway, you're right:&lt;br/&gt;
An official support of ANY_NUM would be great&lt;br/&gt;
 And if I could add this to my whishlist:&lt;br/&gt;
OVERLOADING of methods!!!!&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;I want to raise my hand also for overloading.  Also I wish CoDeSys would give more document how to use the following types:&lt;/p&gt;
&lt;p&gt;ANY &lt;br/&gt;
ANY_DERIVED &lt;br/&gt;
ANY_ELEMENTARY &lt;br/&gt;
ANY_MAGNITUDE &lt;br/&gt;
ANY_BIT &lt;br/&gt;
ANY_STRING &lt;br/&gt;
ANY_DATE &lt;br/&gt;
ANY_NUM &lt;br/&gt;
ANY_REAL &lt;br/&gt;
ANY_INT&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Variable name to string</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/15f032303a/?limit=25#72d3" rel="alternate"/><published>2020-02-27T14:11:48.613000Z</published><updated>2020-02-27T14:11:48.613000Z</updated><author><name>singleton</name><uri>https://forge.codesys.com/u/singleton/</uri></author><id>https://forge.codesys.com51e819b0b150d70fde4bcdf141610f2d7c890526</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi Strucc,&lt;br/&gt;
he was asking for variable instances not for FB instances. That's why I did not offer this instance-path stuff &lt;/p&gt;
&lt;p&gt;But anyway, you're right:&lt;br/&gt;
An official support of ANY_NUM would be great  &lt;/p&gt;
&lt;p&gt;And if I could add this to my whishlist:&lt;br/&gt;
OVERLOADING of methods!!!!&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Variable name to string</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/15f032303a/?limit=25#302f" rel="alternate"/><published>2020-02-27T14:11:47.528000Z</published><updated>2020-02-27T14:11:47.528000Z</updated><author><name>Strucc</name><uri>https://forge.codesys.com/u/strucc/</uri></author><id>https://forge.codesys.comead15b2f46e8580d32529afb49263e80bdf878de</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;jzhvymetal hat geschrieben:&lt;/strong&gt;&lt;br/&gt;
Is there any way to get the name and type of current variable in runtime.&lt;br/&gt;
for example&lt;br/&gt;
myDINT: DINT;&lt;br/&gt;
myCurrentVariableName: STRING; &lt;br/&gt;
myCurrentVariableName := toString(myDINT);  (&lt;em&gt; myCurrentVariableName would equal "myDINT" &lt;/em&gt;)&lt;br/&gt;
if TYPE(myDINT) = DINT then&lt;br/&gt;
      (&lt;em&gt; True if variable is DINT &lt;/em&gt;)&lt;br/&gt;
endif&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Try to search for "{attribute reflection}" and "{attribute instance-path}".&lt;br/&gt;
This works for FB instances... I quote online help....&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;attribute&lt;/span&gt; &lt;span class="err"&gt;'reflection'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="nt"&gt;FUNCTION_BLOCK&lt;/span&gt; &lt;span class="nt"&gt;POU&lt;/span&gt; 
&lt;span class="nt"&gt;VAR&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;attribute&lt;/span&gt; &lt;span class="err"&gt;'instance-path'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="err"&gt;attribute&lt;/span&gt; &lt;span class="err"&gt;'noinit'&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt; 
&lt;span class="nt"&gt;str&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;STRING&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 
&lt;span class="nt"&gt;END_VAR&lt;/span&gt; 
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;In the main program PLC_PRG an instance myPOU of function block POU is called:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nt"&gt;PROGRAM&lt;/span&gt; &lt;span class="nt"&gt;PLC_PRG&lt;/span&gt; 
&lt;span class="nt"&gt;VAR&lt;/span&gt; 
&lt;span class="nt"&gt;myPOU&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="nd"&gt;POU&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 
&lt;span class="nt"&gt;myString&lt;/span&gt;&lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;STRING&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 
&lt;span class="nt"&gt;END_VAR&lt;/span&gt; 
&lt;span class="nt"&gt;myPOU&lt;/span&gt;&lt;span class="o"&gt;();&lt;/span&gt; 
&lt;span class="nt"&gt;myString&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt;&lt;span class="nt"&gt;myPOU&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;str&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt; 
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;And... you can always check an FB instance for interface compatibility....&lt;br/&gt;
(instead of types)&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Variable name to string</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/15f032303a/?limit=25#3cfd" rel="alternate"/><published>2020-02-27T14:11:47.183000Z</published><updated>2020-02-27T14:11:47.183000Z</updated><author><name>Strucc</name><uri>https://forge.codesys.com/u/strucc/</uri></author><id>https://forge.codesys.com968a77560200054717133041c3b09ae7962bec3f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;By the way, would be nice from 3S to release documentation on type independent numeric variables ANY_NUM.... &lt;br/&gt;
I know, this must work internally.... And sometimes it's useful when developing more or less generic FBs, libraries....&lt;/p&gt;
&lt;p&gt;Also, I've noticed, that some functions (MIN, MAX) can receive more than 2 parameters in ST? &lt;/p&gt;
&lt;p&gt;How to declare such user functions?&lt;/p&gt;
&lt;p&gt;P.&lt;/p&gt;
&lt;p&gt;These are really CoDeSys internals... but this features are making things elegant and excellent....&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Variable name to string</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/15f032303a/?limit=25#1608" rel="alternate"/><published>2020-02-27T14:11:46.803000Z</published><updated>2020-02-27T14:11:46.803000Z</updated><author><name>singleton</name><uri>https://forge.codesys.com/u/singleton/</uri></author><id>https://forge.codesys.com071ba32584e68090134260188b31c68052a22a28</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Hi,&lt;br/&gt;
to get the type of a variable you can use conditional pragmas:&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="n"&gt;PROGRAM&lt;/span&gt; &lt;span class="n"&gt;POU&lt;/span&gt;
&lt;span class="n"&gt;VAR&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;iMyValue&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt;  &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;INT&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="n"&gt;xIsInteger&lt;/span&gt;&lt;span class="err"&gt; &lt;/span&gt; &lt;span class="err"&gt;  &lt;/span&gt; &lt;span class="err"&gt; &lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;BOOL&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="n"&gt;END_VAR&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;


&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;{&lt;span class="k"&gt;IF&lt;/span&gt; &lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;hastype&lt;/span&gt;&lt;span class="ss"&gt;(&lt;/span&gt;&lt;span class="nv"&gt;variable&lt;/span&gt; : &lt;span class="nv"&gt;iMyValue&lt;/span&gt;, &lt;span class="nv"&gt;INT&lt;/span&gt;&lt;span class="ss"&gt;))&lt;/span&gt;}
   &lt;span class="nv"&gt;xIsInteger&lt;/span&gt; :&lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nv"&gt;TRUE&lt;/span&gt;&lt;span class="c1"&gt;;&lt;/span&gt;
{&lt;span class="nv"&gt;END_IF&lt;/span&gt;}
&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;To get the name of a variable you can try the attribute ```&lt;/p&gt;
&lt;p&gt;'parameterstringof'&lt;/p&gt;
&lt;p&gt;``` But as far as I know this is only working inside visualizations.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Variable name to string</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/15f032303a/?limit=25#7133" rel="alternate"/><published>2020-02-27T14:11:46.459000Z</published><updated>2020-02-27T14:11:46.459000Z</updated><author><name>jzhvymetal</name><uri>https://forge.codesys.com/u/jzhvymetal/</uri></author><id>https://forge.codesys.comde483d0c947de844ff4e8fcd16ff95138f9ca14e</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Is there any way to get the name and type of current variable in runtime.&lt;/p&gt;
&lt;p&gt;for example&lt;/p&gt;
&lt;p&gt;myDINT: DINT;&lt;br/&gt;
myCurrentVariableName: STRING; &lt;/p&gt;
&lt;p&gt;myCurrentVariableName := toString(myDINT);  (&lt;em&gt; myCurrentVariableName would equal "myDINT" &lt;/em&gt;)&lt;/p&gt;
&lt;p&gt;if TYPE(myDINT) = DINT then&lt;br/&gt;
      (&lt;em&gt; True if variable is DINT &lt;/em&gt;)&lt;br/&gt;
endif&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>