Adding leading zero

Technical support and scripting issues

Moderators: Dorian (MJT support), JRL

Post Reply
User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Adding leading zero

Post by Phil Pendlebury » Mon Feb 19, 2007 9:34 am

Hi again,

In one of my scripts I have a file counter which adds a number to a file name.

Users have pointed out that adding 1_filename, 2_filename etc. causes sorting problems in explorer.

Is there an obvious way to add leading zero?

01_filename, 02_filename etc.

TY.
Phil Pendlebury - Linktree

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Feb 19, 2007 9:43 am

This adds one leading zero and keeps the length of the string to two digits.

Code: Select all

VBSTART
VBEND

Let>kount=1
VBEval>Left("0" & "%kount%",2),kount

Let>filename=%kount%_filename

Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Mon Feb 19, 2007 10:33 am

Did the job great except had to add:

Code: Select all

IF>kount<10
ENDIF

etc.

as it was stripping the 1st digit from any number greater than 10.

Thanks, I wish I knew more about he VB stuff it is obviously really handy.
Last edited by Phil Pendlebury on Mon Feb 19, 2007 11:07 am, edited 1 time in total.
Phil Pendlebury - Linktree

User avatar
Marcus Tettmar
Site Admin
Posts: 7380
Joined: Thu Sep 19, 2002 3:00 pm
Location: Dorset, UK
Contact:

Post by Marcus Tettmar » Mon Feb 19, 2007 10:48 am

I think I should have used Right. And I would also use more zeros/longer string:

Code: Select all

VBSTART
VBEND

Let>kount=1
VBEval>Right("0000" & "%kount%",4),kount
This would yield 0001 to 9999. If your numbers are in that range they would not get truncated and would have leading zeros (where less than 4 digits).
Marcus Tettmar
http://mjtnet.com/blog/ | http://twitter.com/marcustettmar

Did you know we are now offering affordable monthly subscriptions for Macro Scheduler Standard?

User avatar
Phil Pendlebury
Automation Wizard
Posts: 538
Joined: Tue Jan 16, 2007 9:00 am
Contact:

Post by Phil Pendlebury » Mon Feb 19, 2007 11:08 am

Aha...

Well both solutions work for me and both help me learn more about how the commands work which is great.

Thank you once again.
Phil Pendlebury - Linktree

Post Reply
Sign up to our newsletter for free automation tips, tricks & discounts