<?xml version="1.0" encoding="utf-8"?>
<feed xml:lang="en" xmlns="http://www.w3.org/2005/Atom"><title>Recent posts to Leading Zeros</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/" rel="alternate"/><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/feed.atom" rel="self"/><id>https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/</id><updated>2021-01-22T14:25:37.071000Z</updated><subtitle>Recent posts to Leading Zeros</subtitle><entry><title>Leading Zeros</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/?limit=25#0678" rel="alternate"/><published>2021-01-22T14:25:37.071000Z</published><updated>2021-01-22T14:25:37.071000Z</updated><author><name>davejc</name><uri>https://forge.codesys.com/u/davejc/</uri></author><id>https://forge.codesys.comcdb5dbe9f6bfceb9123a6602a501b5539d6f1e08</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Got it.  Just incase any one else comes across this....&lt;/p&gt;
&lt;p&gt;GVLP.iBatchID := GVLP.iBatchID + 1;&lt;br/&gt;
GVLP.wsBatchID := WConcat("0000", INT_TO_WSTRING(GVLP.iBatchID));&lt;br/&gt;
GVLP.wsBatchID := WRight(GVLP.wsBatchID,5);&lt;br/&gt;
GVLP.wsBatchID := WConcat("RUNA",GVLP.wsBatchID);&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Leading Zeros</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/?limit=25#1d74" rel="alternate"/><published>2021-01-22T13:20:59.098000Z</published><updated>2021-01-22T13:20:59.098000Z</updated><author><name>davejc</name><uri>https://forge.codesys.com/u/davejc/</uri></author><id>https://forge.codesys.com72b8a2333f2d3d6da98a81d629a7c65bd3637720</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;So I've had some more thoughts on this and I am wondering if commands exist that will let me do this....&lt;/p&gt;
&lt;p&gt;Take the iBatchID Integer and concat together "0000" and iBatchID to get "0000###".  Then is there a command where I can take just the 5 characters from the Right of this?  Thus removing the excess leading 0's?  Then I can use another concat to put "RUNA" in front of it.&lt;/p&gt;
&lt;p&gt;Obviously I know concat is there, but is there a command that will allow me to just select the 5 characters from right to left ??&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Leading Zeros</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/?limit=25#7ea1/3b89" rel="alternate"/><published>2021-01-14T20:47:28.181000Z</published><updated>2021-01-14T20:47:28.181000Z</updated><author><name>i-campbell</name><uri>https://forge.codesys.com/u/i-campbell/</uri></author><id>https://forge.codesys.comb041636f4e11a4a02c5f19cfff65da2e2d5a2201</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Are you in simulation mode? This only works when not in Simulation mode.&lt;br/&gt;
You can use the Soft PLC that comes with the IDE installer. Just start it from the Systray.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Leading Zeros</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/?limit=25#cfa3" rel="alternate"/><published>2021-01-14T20:40:06.774000Z</published><updated>2021-01-14T20:40:06.774000Z</updated><author><name>davejc</name><uri>https://forge.codesys.com/u/davejc/</uri></author><id>https://forge.codesys.com9feeb372f5d537abd9e31fa2bbf4c3824bc8957f</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I may not be following what youre trying to explain and I apologize if that is the case.  What I have found is...&lt;/p&gt;
&lt;p&gt;if I create a text block on my VISU and set the text to "RUNA%05d" then set the text variable to "GVLP.iBatchID", this outputs exactly what I need "RUNA0001, RUNA0002, etc.".  I just don't know to get that string into a Variable that I can use elsewhere.  It would be great if I could use the concat and somehow tell it to use the format %05d for the Integer when concat'ing.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Leading Zeros</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/?limit=25#7ea1" rel="alternate"/><published>2021-01-14T20:00:36.538000Z</published><updated>2021-01-14T20:00:36.538000Z</updated><author><name>davejc</name><uri>https://forge.codesys.com/u/davejc/</uri></author><id>https://forge.codesys.comde1aee0c3b9450ed0583a45bb052d4a86cd5c1e3</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I have to be missing something here.  I am unsure what output I should be getting from the StuSprintfW function.&lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Leading Zeros</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/?limit=25#b60c" rel="alternate"/><published>2021-01-14T19:37:32.454000Z</published><updated>2021-01-14T19:37:32.454000Z</updated><author><name>i-campbell</name><uri>https://forge.codesys.com/u/i-campbell/</uri></author><id>https://forge.codesys.com4f4b9f1f96da35a3cf6da434849af62ed4315819</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Ah ok.  I guess a REAL value will still work as good, I just find it strange to use a REAL when I will never have any decimal places.&lt;br/&gt;
Here is another one, which does exactly the same thing as the first.&lt;/p&gt;
&lt;div class="codehilite"&gt;&lt;pre&gt;&lt;span&gt;&lt;/span&gt;&lt;span class="nc"&gt;PROGRAM&lt;/span&gt; &lt;span class="nf"&gt;PLC_PRG_1&lt;/span&gt;
&lt;span class="nf"&gt;VAR&lt;/span&gt;
    &lt;span class="nf"&gt;Format&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;WSTRING&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="c"&gt;"RUNA%05d"&lt;/span&gt;;
    &lt;span class="nc"&gt;ID&lt;/span&gt;     &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;UDINT&lt;/span&gt;    &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="m"&gt;254&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nf"&gt;wsBatchID&lt;/span&gt; &lt;span class="err"&gt;:&lt;/span&gt; &lt;span class="nf"&gt;WSTRING&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="c"&gt;"UNDEFINED"&lt;/span&gt;;
&lt;span class="nf"&gt;END_VAR&lt;/span&gt;

&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="nc"&gt;Requires&lt;/span&gt; &lt;span class="nf"&gt;StringUtils&lt;/span&gt; &lt;span class="nf"&gt;library&lt;/span&gt;
&lt;span class="nf"&gt;StuSprintfW&lt;/span&gt;(
    &lt;span class="err"&gt;wstFormat&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nc"&gt;ADR&lt;/span&gt;(&lt;span class="nc"&gt;Format&lt;/span&gt;)&lt;span class="nf"&gt;,&lt;/span&gt; 
    &lt;span class="err"&gt;pVarAdr&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nc"&gt;ADR&lt;/span&gt;(&lt;span class="nc"&gt;ID&lt;/span&gt;)&lt;span class="nf"&gt;,&lt;/span&gt; 
    &lt;span class="err"&gt;udiVarType&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="o"&gt;__&lt;/span&gt;&lt;span class="err"&gt;SYSTEM&lt;/span&gt;.&lt;span class="nc"&gt;TYPE_CLASS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TYPE_UDINT&lt;/span&gt;&lt;span class="nf"&gt;,&lt;/span&gt; 
    &lt;span class="err"&gt;pBuffer&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nc"&gt;ADR&lt;/span&gt;(&lt;span class="nv"&gt;wsBatchID&lt;/span&gt;)&lt;span class="nf"&gt;,&lt;/span&gt; 
    &lt;span class="err"&gt;dwBufferSize&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nc"&gt;SIZEOF&lt;/span&gt;(&lt;span class="nv"&gt;wsBatchID&lt;/span&gt;))&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Leading Zeros</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/?limit=25#42ab" rel="alternate"/><published>2021-01-14T19:30:37.467000Z</published><updated>2021-01-14T19:30:37.467000Z</updated><author><name>davejc</name><uri>https://forge.codesys.com/u/davejc/</uri></author><id>https://forge.codesys.comada6c2a2dda8e1d688e0e165a6f96a969338e7de</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;"Why is your batchid a real, if you only have integer values?"  because I don't necessarily know EXACTLY what I'm doing.&lt;/p&gt;
&lt;p&gt;How would that logic be modified if I were to use Integer rather than Real?  &lt;/p&gt;&lt;/div&gt;</summary></entry><entry><title>Leading Zeros</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/?limit=25#904a" rel="alternate"/><published>2021-01-14T19:21:55.042000Z</published><updated>2021-01-14T19:21:55.042000Z</updated><author><name>i-campbell</name><uri>https://forge.codesys.com/u/i-campbell/</uri></author><id>https://forge.codesys.comec52aac52180517cd3de30b466b20fffd6ddcf99</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;Why is your batchid a real, if you only have integer values?&lt;br/&gt;
Anyway, for a REAL you can do:&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;Format&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;WSTRING&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s2"&gt;"RUNA%05.0f"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;ID&lt;/span&gt;     &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;REAL&lt;/span&gt;    &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;254&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;0&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
    &lt;span class="nt"&gt;wsBatchID&lt;/span&gt; &lt;span class="o"&gt;:&lt;/span&gt; &lt;span class="nt"&gt;WSTRING&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="s2"&gt;"UNDEFINED"&lt;/span&gt;&lt;span class="o"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;END_VAR&lt;/span&gt;

&lt;span class="o"&gt;//&lt;/span&gt;&lt;span class="nt"&gt;Requires&lt;/span&gt; &lt;span class="nt"&gt;StringUtils&lt;/span&gt; &lt;span class="nt"&gt;library&lt;/span&gt;
&lt;span class="nt"&gt;StuSprintfW&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;
    &lt;span class="nt"&gt;wstFormat&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;ADR&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;Format&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; 
    &lt;span class="nt"&gt;pVarAdr&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;ADR&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;ID&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; 
    &lt;span class="nt"&gt;udiVarType&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;__SYSTEM&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TYPE_CLASS&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nc"&gt;TYPE_REAL&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; 
    &lt;span class="nt"&gt;pBuffer&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;ADR&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;wsBatchID&lt;/span&gt;&lt;span class="o"&gt;),&lt;/span&gt; 
    &lt;span class="nt"&gt;dwBufferSize&lt;/span&gt;&lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="nt"&gt;SIZEOF&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;wsBatchID&lt;/span&gt;&lt;span class="o"&gt;));&lt;/span&gt;
&lt;/pre&gt;&lt;/div&gt;

&lt;/div&gt;</summary></entry><entry><title>Leading Zeros</title><link href="https://forge.codesys.com/forge/talk/Engineering/thread/f05178ced3/?limit=25#f32d" rel="alternate"/><published>2021-01-14T18:55:24.064000Z</published><updated>2021-01-14T18:55:24.064000Z</updated><author><name>davejc</name><uri>https://forge.codesys.com/u/davejc/</uri></author><id>https://forge.codesys.com3f77b210116f3b7cf05c3e1fdc2204dabbd05917</id><summary type="html">&lt;div class="markdown_content"&gt;&lt;p&gt;I am working on a project where I am trying to create a default string that is "RUNA#####", where ##### starts at "0001" and increments based on some other logic.&lt;/p&gt;
&lt;p&gt;I am able to make this work using the logic:&lt;br/&gt;
    GVLP.rBatchID := GVLP.rBatchID +1;&lt;br/&gt;
    GVLP.wsBatchID:= WConcat("RUNA",REAL_TO_WSTRING(GVLP.rBatchID));&lt;/p&gt;
&lt;p&gt;The problem I am having it getting the RealValue to always be 5 Digits.&lt;/p&gt;
&lt;p&gt;Has anyone tried to do this and/or have any tips what I can try to get this to work??&lt;/p&gt;&lt;/div&gt;</summary></entry></feed>