WinBatch® Technical Support Forum

All Things WinBatch => WinBatch => Topic started by: twb on August 05, 2013, 12:02:38 PM

Title: Retain leading zeros
Post by: twb on August 05, 2013, 12:02:38 PM
I searched the manual and the forums for an answer but must not be using the correct search terms.

I'm building a string of data to pass to a program called with FTP using rcmd in my FTP script.  Building a parameter string manually and calling the program works fine.  For production I will be building the string from array values. The issue I am having is one of the values is a count of errors.   In the example string below "dtlcnt" is my count of errors. I am wanting a 2 digit value and need to retain the leading zero. '07', not '7 '.

dtlcnt is the number of array elements, up to 99.

newString1 = StrInsert(newString1,dtlcnt,' ',12,2)

Is there a way to define an edit code so the leading zero is not suppressed? 

Coding the following works but to me isn't ideal:

      if dtlcnt < 10
         newString1 = StrInsert(newString1,'0',' ',12,1)
         newString1 = StrInsert(newString1,dtlcnt,' ',13,1)
      else;
         newString1 = StrInsert(newString1,dtlcnt,' ',12,2)
      endif

Thank you,
Tom

Title: Re: Retain leading zeros
Post by: JTaylor on August 05, 2013, 12:43:27 PM
Take a look at StrFixLeft().

Jim
Title: Re: Retain leading zeros
Post by: twb on August 05, 2013, 12:53:40 PM
Thank you Jim.

The following worked:

newString1 = StrInsert(newString1,StrFixLeft(dtlcnt, "0", 2),' ',12,2)